CMD中的ISO周数 [英] ISO week number in CMD
问题描述
如何在Windows批处理文件中确定( ISO 8601 )周号?
How can I determine the (ISO 8601) week number in a Windows batch file?
不幸的是 WMIC PATH WIN32_LOCALTIME GET / FORMAT:LIST
只有 WeekInMonth ...
Unfortunately WMIC PATH WIN32_LOCALTIME GET /FORMAT:LIST
only has WeekInMonth...
我发现一些非常< a> 复杂 解决方案。有没有更简单的方法?
I have found some very complex solutions. Is there no easier way?
推荐答案
这个工作可以到2100年3月6日:
This will work up to March 6th, 2100:
FOR /f %%a IN ('WMIC PATH WIN32_LOCALTIME GET /FORMAT:LIST') DO @(SET %%a>NUL)
SET /A a=(14-%Month%)/12,y=%Year%-a,IsoWeek=(%Day%+(153*(%Month%+12*a-3)+2)/5+365*y+y/4)/7-(365*%Year%+(%Year%+3)/4)/7+9
第一行将 WMIC
输出放入环境变量中。第二行使%IsoWeek%
包含ISO周数。它将包含每年1月4日的1。
The first line puts the WMIC
output into environment variables. The second line makes %IsoWeek%
contain the ISO week number. It will contain 1 for January 4th of each year.
异常: 0
意味着它是上一个年(52或53),有时是53,实际上是明年的第1周。确定这些年度边界将进一步使计算复杂化。
Exception: 0
means it's the last week of the previous year (52 or 53) and sometimes it's 53 where it should actually be week 1 of the next year. Fixing these year boundaries would further complicate the calculations.
这篇关于CMD中的ISO周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!