如何在PowerShell中格式化DateTime [英] How to format a DateTime in PowerShell
本文介绍了如何在PowerShell中格式化DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以格式化 获取日期
cmdlet像这样没有问题:
I can format the Get-Date
cmdlet no problem like this:
$date = Get-Date -format "yyyyMMdd"
但是一旦我得到日期在变量中,该如何格式化?下面的语句
But once I've got a date in a variable, how do I format it? The statement below
$dateStr = $date -format "yyyMMdd"
返回此错误:
您必须提供一个值表达式$ b-b位于'-f'
运算符的右侧
"You must provide a value expression on the right-hand side of the '-f' operator"
推荐答案
与在。NET :
$DateStr = $Date.ToString("yyyyMMdd")
或:
$DateStr = '{0:yyyyMMdd}' -f $Date
这篇关于如何在PowerShell中格式化DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文