Current_Path 获取脚本所在路径(当前路径),取当前时间做文件名(uformat)
获取脚本当前所在路径:
$CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand.Path.LastIndexOf('\')+1)
$today = Get-Date -UFormat "%Y%m%d"
$LogFilePath = $CurrentPath+"Result_$today.txt"
get-process |out-file $LogFilePath -Append
$Currentpath = Split-Path -parent $MyInvocation.MyCommand.Definition
格式化日期:
$now = get-date -format 'yyyyMMddHHmm'
$dpunmountcmd_ScriptName = "DPUnmount_script_" + $now + ".txt"
$yes = (get-date).adddays(-1)
get-date -date $yes -uformat "%Y/%M/%d" 输出: 2014/06/23
$yes.tostring("yyyy\/MM\/dd") 输出: 2014/06/23
Get-Date使用Format参数考取年、月、日、时、分、秒
yyyy 年
M 月
d 日
h 小时(12小时制)
H 小时(24小时制)
m 分钟
s 秒
Get-Date -UFormat "%Y/%m/%d" :2014/04/18
get-date -uformat %R :11:07
==============================
Get-Date -UFormat %<value>
For example,
Get-Date -UFormat %d
Date-Time:
Date and time - full
(default) (Friday, June 16, 2006 10:31:27 AM)
c Date and time - abbreviated (Fri Jun 16 10:31:27 2006)
Date:
D Date in mm/dd/yy format (06/14/06)
x Date in standard format for locale (09/12/07 for English-US)
Year:
C Century (20 for 2006)
Y Year in 4-digit format (2006)
y Year in 2-digit format (06)
G Same as 'Y'
g Same as 'y'
Month:
b Month name - abbreviated (Jan)
B Month name - full (January)
h Same as 'b'
m Month number (06)
Week:
W Week of the year (00-52)
V Week of the year (01-53)
U Same as 'W'
Day:
a Day of the week - abbreviated name (Mon)
A Day of the week - full name (Monday)
u Day of the week - number (Monday = 1)
d Day of the month - 2 digits (05)
e Day of the month - digit preceded by a space ( 5)
j Day of the year - (1-366)
w Same as 'u'
Time:
p AM or PM
r Time in 12-hour format (09:15:36 AM)
R Time in 24-hour format - no seconds (17:45)
T Time in 24 hour format (17:45:52)
X Same as 'T'
Z Time zone offset from Universal Time Coordinate (UTC) (-07)
Hour:
H Hour in 24-hour format (17)
I Hour in 12 hour format (05)
k Same as 'H'
l Same as 'I' (Upper-case I = Lower-case L)
Minutes & Seconds:
M Minutes (35)
S Seconds (05)
s Seconds elapsed since January 1, 1970 00:00:00 (1150451174.95705)
Special Characters:
n newline character (\n)
t Tab character (\t)
详细参考:http://www.cnblogs.com/dreamer-fish/p/3805726.html
From:http://technet.microsoft.com/zh-cn/library/hh849887.aspx
Current_Path 获取脚本所在路径(当前路径),取当前时间做文件名(uformat)的更多相关文章
- Delphi获取文件名、文件名不带扩展名、文件名的方法;delphi 获取文件所在路径
取文件名 ExtractFileName(FileName); 取文件扩展名: ExtractFileExt(filename); 取文件名,不带扩展名: 方法一: Function Extrac ...
- bat(续五)-获取批处理文件所在路径
获取批处理文件所在路径 在开发时,经常需要使用批处理运行一些程序,java程序 犹其是这样,往往需要运行时根路径.Hardcode一个路径总是令自己觉得不自在,例如一个java程序从一台 ...
- C#: 获取执行程序所在路径和启动资源管理器
一. 获取执行程序所在路径 1.获取和设置当前目录的完全限定路径. string str = System.Environment.CurrentDirectory; //获取的是主程序目录,线程启 ...
- delphi根据进程PID获取程序所在路径的函数(用OpenProcess取得句柄,用GetModuleFileNameEx取得程序名)
uses psapi; {根据进程PID获取程序所在路径的函数}function GetProcessExePath(PID: Cardinal): string;varpHandle: THandl ...
- Qt 程序获取程序所在路径、用户目录路径、临时文件夹等特殊路径的方法
Qt 程序获取程序所在路径.用户目录路径.临时文件夹等特殊路径的方法 经常我们的程序中需要访问一些特殊的路径,比如程序所在的路径.用户目录路径.临时文件夹等.在 Qt 中实现这几个功能所用的方法虽然都 ...
- Application.StartupPath获取执行文件路径substring()取特定长度字符串取得根目录
Application.StartupPath获取执行文件路径substring()取特定长度字符串取得根目录 2012-07-20 10:48 257人阅读 评论(0) 收藏 举报 path usi ...
- dotnet 获取程序所在路径的方法
在 dotnet 有很多方法可以获取当前程序所在的路径,但是这些方法获取到的路径有一点不相同,特别是在工作路径不是当前的程序所在的路径的时候 通过下面几个方法都可以拿到程序所在的文件夹或程序文件 Ap ...
- python 获取脚本所在目录
平时写python经常会想获得脚本所在的目录,例如有个文件跟脚本文件放在一个相对的目录位置,那就可以通过脚本文件的目录找到对应的文件,即使以后脚本文件移到其他地方,脚本也基本不需要改动(相对于写死目录 ...
- 批处理文件中获取当前所在路径的几种方法,以及写文件到txt
@echo off setlocal EnableDelayedExpansion echo 当前正在运行的批处理文件所在路径:!cd! pause @echo off echo 当前目录是:%cd% ...
随机推荐
- nginx安装及其配置详细教程
1 nginx 介绍 1 什么是nginx Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器. 由俄罗斯的程序设计师Igor Sysoev所开发,官方 ...
- Install Papirus Icon Theme on Ubuntu
sudo add-apt-repository ppa:papirus/papirus sudo apt update && sudo apt install papirus-icon ...
- PHP之mb_check_encoding使用
mb_check_encoding (PHP 4 >= 4.4.3, PHP 5 >= 5.1.3, PHP 7) mb_check_encoding - Check if the str ...
- 吴恩达《深度学习》第四门课(3)目标检测(Object detection)
3.1目标定位 (1)案例1:在构建自动驾驶时,需要定位出照片中的行人.汽车.摩托车和背景,即四个类别.可以设置这样的输出,首先第一个元素pc=1表示有要定位的物体,那么用另外四个输出元素表示定位框的 ...
- WCF Data Services 5.0 for OData V3
https://www.microsoft.com/en-us/download/details.aspx?id=29306 VS 2010 下 安装 WCF Data Services 5.0 en ...
- Menustrip控件和ContextMenustrip控件
Menustrip 控件是由System.Windows.Forms.Menustrip类提供,取代了以前的MainMenu控件,是应用程序菜单结构的容器,在建立菜单时,要给Menustrip控件添加 ...
- MySQL---4、语句规范
1.命名规范 (1)库名.表名.(按现在的规范类似; PromoHayaoRecord),数据库名使用小写,字段名必须使用小写字母,并采用下划线分割.关键字与函数名称全部大写.(2)库名.表名.字段名 ...
- mysql 登录报错:ERROR 1045 (28000)
公司linux系统的mysql数据库root用户设置过密码,但常常用命令'mysql -u root -p'登录报错,有时又能登录.登录报错信息为: [root@localhost ~]# mysql ...
- 简单明了区分escape、encodeURI和encodeURIComponent(转)
一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...
- Vue2.0实现ie的兼容
转自:https://blog.csdn.net/landl_ww/article/details/79149461 1.解决方案:安装 "babel-polyfill" ,加配置 ...