gpt4 book ai didi

powershell - 使用 powershell 获取当月的天数

转载 作者:行者123 更新时间:2023-12-03 23:31:30 24 4
gpt4 key购买 nike

我需要检索当月的天数,尽管我进行了研究,但我还没有在 powershell 中找到任何可以做到这一点的东西。以下是我目前为获得我想要的结果而构建的内容。有更好的方法吗?

请注意,我仅限于 Powershell

    #check to see if this is a leap year
function LYC
{
if ([System.DateTime]::isleapyear((Get-Date).Year))
{
$Global:LY = True
}
}
#Get the number of days in current month
function fNOD
{
$MNum = (Get-Date).Month
switch ($MNum)
{
1 {$Global:DaysInMonth=31}
2 {
LYC
if (LY)
{
$Global:DaysInMonth=29
} else {
$Global:DaysInMonth=28
}
}
3 {$Global:DaysInMonth=31}
4 {$Global:DaysInMonth=30}
5 {$Global:DaysInMonth=31}
6 {$Global:DaysInMonth=30}
7 {$Global:DaysInMonth=31}
8 {$Global:DaysInMonth=31}
9 {$Global:DaysInMonth=30}
10 {$Global:DaysInMonth=31}
11 {$Global:DaysInMonth=30}
12 {$Global:DaysInMonth=31}
}
}

最佳答案

http://msdn.microsoft.com/en-us/library/system.datetime.daysinmonth.aspx

# static int DaysInMonth(int year, int month)
[DateTime]::DaysInMonth(2013, 3)

关于powershell - 使用 powershell 获取当月的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15469185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com