在Powershell中获取给定日期的ISO 8601年度周 [英] Get the ISO 8601 Week of Year of a given date in Powershell
问题描述
在搜索如何在PowerShell中获取一年中的ISO 8601星期时,我已经偶然发现此C#问题.
While searching how to get the ISO 8601 Week of Year in PowerShell, I've stumbled upon this question for C#.
尽量不要在PowerShell代码中挤这个问题,这是我下面的Powershell端口.(基于用户6887101的回答)
Trying not to crowd that question with PowerShell code, here's my Powershell port below. (based on the answer by user6887101)
如果有人想出更好的解决方案,我会暂时保留这个不被接受".
I'll leave this 'not accepted' for a while in case anyone comes up with a better solution.
推荐答案
聚会晚了一点,但是...只是要把答案留在这里,因为这个问题是我在寻找解决方案时偶然发现的第一件事对此.有一种更简单的方法:
A little late to the party, but... just going to leave this answer here since this question was the first thing i stumbled upon when looking for a solution to this. There's a much easier way:
获取日期-UFormat%V
OR
"{0:d1}" -f ($(Get-Culture).Calendar.GetWeekOfYear((Get-Date),[System.Globalization.CalendarWeekRule]::FirstFourDayWeek, [DayOfWeek]::Monday))
取决于是否要使用ISO8601.
Depending on if you want ISO8601 or not.
这篇关于在Powershell中获取给定日期的ISO 8601年度周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!