如何在Powershell中获得下一个工作日

How to get the next business day in powershell

我有以下测试代码。基本上我正在检查何时在文件夹中创建了一个新文件。我需要知道如果文件是在下一个工作日显示的下午 4 点之后创建的。目前我的代码显示在第二天,但我需要显示下一个工作日。任何帮助,将不胜感激。

$formatteddate = "{0:h:mm:ss tt}" -f (get-date)

if ($formatteddate -gt "4:00:00 PM"){
$(Get-Date).AddDays(1).ToString('MMM d yyyy')
}

添加到 jisaak 所说的内容:"business day" 是特定于组织的。有些组织不在其他组织的假期工作。如果您想正确处理假期,则需要为您的企业提供明确的假期列表

省略格式细节(OP 似乎理解)应该这样做:

#  $date is input date
$nextBizDay = $date.adddays(1)

# You would probably want to generate the follow list programmatically,
#  instead of manually as done here
$holidays = 1,   <# New Years #>
            18,  <# MLK day 2016 #>
                 <# other holidays encoded as Day Of Year #>
            360  <# Christmas in a Leap Year #>
# An alternative to a list of holidays like this is to find a web service 
#  you can query to get the holidays for a given year

while ($nextBizDay.DayOfWeek -eq 'Saturday' -or
       $nextBizDay.DayOfWeek -eq 'Sunday' -or
       $nextBizDay.DayOfYear -in $holidays) {
  if ($nextBizDay.DayOfYear -gt 366) {
    throw "No next business day this year. Need to add additional logic"
  }
  $nextBizDay = $nextBizDay.adddays(1)
}