一个快速的问题,显然今天(2020年1月6日)的星期数应该是2,因为2020年有53周。
但是,以下PowerShell代码段返回1:
(Get-Date -UFormat %V)
正确获取星期几的最佳方法是什么?
您可以检测到a年,然后根据结果调整星期数。
if(((Get-Date).year)%4 -eq 0){
$week = (Get-Date -UFormat %V) -as [int]
$week++
}else{
$week = (Get-Date -UFormat %V)
}
Write-Host $week