原文地址:http://powershell.com/cs/blogs/tips/archive/2010/06/02/filtering-day-of-week.aspx
原文:
Filtering Day of Week
You can also use this little helper function if you run scripts every day and want to make sure they don't do anything on weekends:
function is-Weekend { (Get-Date).DayOfWeek -gt 5 }
You can use it like this:
If (is-Weekend) { 'no service at weekends' } else { 'Heya, time to work' }
翻译:
判断是否是周末
如果想要判断当前是否是周末,可以用下面这个函数:
function is-Weekend { (Get-Date).DayOfWeek -gt 5 }
然后这样调用:
If (is-Weekend) { '周末休息' } else { '嘿嘿,工作了' }
笔记:
Get-Date有DayOfWeek方法,只要这个数大于5,那么肯定就是周末了。