1

I'm getting the date from a file name "BW-121113-CF1.pdf". So I have my date 121113, how do I figure out what day of the week that was. I tried: "{0:yyMMdd}" -f (get-date) "121113". But of course that didn't work. Any suggestions?

get-date "11/13/12" -format dddd

That get's me the right day of the week. But I need the get-date to understand that "121113" is the say date.

4

2 回答 2

3

尝试这个:

([datetime]::ParseExact("121113", "yyMMdd", 
    [System.Globalization.CultureInfo]::InvariantCulture )).DayOfWeek
于 2012-11-15T05:46:13.280 回答
2

你有很多解决方案:

([datetime]"11/13/12").DayOfWeek")将以 .NET 自然语言为您提供星期几(英文)

尝试 :[datetime]::parse("13/11/2012")

或者 :("{0:dddd}" -f [datetime]::parse("13/11/2012"))

或者 :([datetime]"11/13/2012").tostring("dddd")

在您的特殊情况下:

转换 :$aDate = ("121113" -replace '([0-9]{2})([0-9]{2})([0-9]{2})','$2/$3/$1') 给出 : 11/13/12in $aDate And :([datetime]$aDate).dayofweek

所以 :

([datetime]("121113" -replace '([0-9]{2})([0-9]{2})([0-9]{2})','$2/$3/$1')).dayofweek
于 2012-11-15T04:57:08.440 回答