PowerTip of the Day- Filtering Day of Week

原文地址: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-DateDayOfWeek方法,只要这个数大于5,那么肯定就是周末了。

posted @ 2010-06-03 15:11  哥本哈士奇(aspnetx)  阅读(314)  评论(0编辑  收藏  举报