简体   繁体   English

Powershell Get-Date -Day(新年)

[英]Powershell Get-Date -Day (New Year)

Powershell Get-Date Explanation: Powershell Get-Date说明:

-Day -天

Specifies the day of the month that is displayed. 指定所显示的月份。 Enter a value from 1 to 31. >The default is the current day. 输入1到31之间的一个值。>默认值为当前日期。

If you specify a value that is greater than the number of days in the month, >PowerShell adds the number of days to the month and displays the result. 如果您指定的值大于一个月中的天数,那么> PowerShell会将一个天数添加到该月中并显示结果。 For >example, "Get-Date -Month 2 -Day 31" displays "March 3", not "February 31". 例如,“获取日期-月2-日31”显示“ 3月3日”,而不是“ 2月31日”。

Will this roll over into new year as well, or do I have to adjust code to detect new year if the date ends up transforming into January 1 ? 如果日期最终转换为January 1日,这是否还会延续到新年,还是我必须调整代码以检测新年?

No, it will not roll over, because December has 31 days and anything higher than 31 is an exception. 不,它不会过期,因为12月有31天,任何高于31天的情况都是例外。

Get-Date -Month 2 -Day 32

Result: 结果:

Get-Date : Cannot validate argument on parameter 'Day'. Get-Date:无法验证参数'Day'上的参数。 The 32 argument is greater than the maximum allowed range of 31. Supply an argument that is less than or equal to 31 and then try the command again. 32参数大于最大允许范围31。提供小于或等于31的参数,然后再次尝试命令。
At line:1 char:24 在线:1个字符:24个
+ get-date -month 2 -day 32 +获取日期-第2个月-第32天
+ +
+ CategoryInfo : InvalidData: (:) [Get-Date], ParameterBindingValidationException + CategoryInfo:InvalidData:(:) [获取日期],ParameterBindingValidationException
+ FullyQualifiedErrorId : + FullyQualifiedErrorId:
ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetDateCommand ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetDateCommand

Same for month 12: 第12个月相同:

Get-Date -Month 12 -Day 32

Result 结果

Get-Date : Cannot validate argument on parameter 'Day'. Get-Date:无法验证参数'Day'上的参数。 The 32 argument is greater than the maximum allowed range of 31. Supply an argument that is less than or equal to 31 and then try the command again. 32参数大于最大允许范围31。提供小于或等于31的参数,然后再次尝试命令。
At line:1 char:24 在线:1个字符:24个
+ get-date -month 2 -day 32 +获取日期-第2个月-第32天
+ +
+ CategoryInfo : InvalidData: (:) [Get-Date], ParameterBindingValidationException + CategoryInfo:InvalidData:(:) [获取日期],ParameterBindingValidationException
+ FullyQualifiedErrorId : + FullyQualifiedErrorId:
ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetDateCommand ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetDateCommand

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM