Powershell 替换:替换为u从获取日期结果
我在powershell里找到了约会对象。输出有:我想将其替换为uPowershell 替换:替换为u从获取日期结果,powershell,Powershell,我在powershell里找到了约会对象。输出有:我想将其替换为u Get-Date -format u result 2014-05-14 16:26:45Z 我想将:替换为_ Get-Date -format u | $_ -replace ":","_" 不工作管道的工作方式不太一样 相反,将get date的结果视为对象/变量,并对其使用-replace (get-date -Format u) -replace ":","_"; 或者,因为它只是一个字符串,所以使用re
Get-Date -format u
result
2014-05-14 16:26:45Z
我想将:替换为_
Get-Date -format u | $_ -replace ":","_"
不工作管道的工作方式不太一样 相反,将
get date
的结果视为对象/变量,并对其使用-replace
(get-date -Format u) -replace ":","_";
或者,因为它只是一个字符串,所以使用replace()
方法
(get-date -Format u).Replace(":","_");
您可以执行以下操作:
PS H:\> get-date -format u | % {$_.Replace(":","_")}
2014-05-14 09_41_05Z
PS H:\>
不必事后替换,您只需使用格式说明符即可:
get-date -format 'yyyy-MM-dd HH_mm_ssZ'