我有以下测试代码。基本上我正在检查何时在文件夹中创建新文件。我需要知道,如果文件是在下午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')
}
答案 0 :(得分:3)
添加到jisaak所说的内容:"工作日"是特定于组织的。有些组织不在其他组织的假期工作。如果您想正确处理假期,您需要明确的假期列表
省略格式化细节(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)
}