[英]Convert set date to day of the year
I need to get the day of the year from a set date ie. 我需要从设定的日期即一年中的某一天开始。 05/17/2017 to tell me what the day of the year was. 2017/05/17告诉我一年中的哪一天。
Something somewhat like this ( $b
) only I need it to work. 像这样的东西( $b
)只有我需要它才能工作。
$a = Get-Date
"Day of Year: " + $a.DayOfYear
"date: " + $a
$b = "01/17/2018"
"set date: " + $b
"set day of year: " + $b.DayOfYear
You can do so by using either the PowerShell Cmdlet Get-Date
or by parsing it using ParseExact
method of DateTime
. 您可以使用PowerShell Cmdlet Get-Date
或使用DateTime
ParseExact
方法对其进行解析来实现。
$date = Get-Date -Date $b;
$template = 'MM/dd/yyyy'
$date = [DateTime]::ParseExact("01/17/2018", $template, $null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.