Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何从数学上找到下面最近的奇数月_Powershell_Date Arithmetic - Fatal编程技术网

Powershell 如何从数学上找到下面最近的奇数月

Powershell 如何从数学上找到下面最近的奇数月,powershell,date-arithmetic,Powershell,Date Arithmetic,PowerShell返回当前月份,其中包含: (Get-Date).Month 但我需要知道下面最接近的奇数月 如果每个月在一年内由匹配的数字表示: 1 → 1 2 → 1 3 → 3 4 → 3 5 → 5 6 → 5 7 → 7 8 → 7 9 → 9 10 → 9 11 → 11 12 → 11 1.→ 1. 2.→ 1. 3.→

PowerShell返回当前月份,其中包含:

(Get-Date).Month
但我需要知道下面最接近的奇数月

如果每个月在一年内由匹配的数字表示:

1 → 1 2 → 1 3 → 3 4 → 3 5 → 5 6 → 5 7 → 7 8 → 7 9 → 9 10 → 9 11 → 11 12 → 11 1.→ 1. 2.→ 1. 3.→ 3. 4.→ 3. 5.→ 5. 6.→ 5. 7.→ 7. 8.→ 7. 9→ 9 10→ 9 11→ 11
12→ 11检查是否可被2整除:

$m = (Get-Date).Month
if ($m % 2 -eq 0) { 
  $m -= 1 
} 

Write-Host $m
证明:

1..12 | % { Write-Host -nonewline "$_ ==> " ; if ($_ % 2 -eq 0 ) { $_ -= 1} ; Write-Host $_ }

好的谢谢:-)几个小时以来一直在用商、模运算,试图从结果中添加或删除1…不客气!如果这有助于解决我的问题,请告诉我,但我是新来的,没有足够的声誉。。。此外,有人投票认为我的问题没有用,这降低了我的声誉。。。lol@Luke好吧,不管你的声誉有多低,你都应该能够接受你问题的答案。你这样做也应该得到一些代表分数。
[int][Math]::Floor((获取日期)。Month-1)/2)*2+1
哦!你找到它的方式,我正在寻找。。。现在我有两个有效的解决方案:-)