PowerTip of the Day- Filtering Day of Week
2010-06-03 15:11
537 查看
原文地址: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,那么肯定就是周末了。
原文:
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,那么肯定就是周末了。
相关文章推荐
- PowerTip of the Day from powershell.com上周汇总
- PowerTip of the Day-Finding Invalid Aliases
- PowerTip of the Day from powershell.com上周汇总(八)
- PowerTip of the Day from powershell.com上周汇总(九)
- PowerTip of the Day from powershell.com上周汇总(十一)
- PowerTip of the Day from powershell.com上周汇总(二)
- PowerTip of the Day-Getting Installed Updates
- PowerTip of the Day from powershell.com上周汇总
- PowerTip of the Day from powershell.com上周汇总(四)
- PowerTip of the Day from powershell.com上周汇总(七)
- PowerTip of the Day-Create Remoting Solutions
- PowerTip of the Day-Creating Your Own Types
- PowerTip of the Day-Add Help to Your Functions
- PowerTip of the Day from powershell.com上周汇总(九)
- PowerTip of the Day from powershell.com上周汇总(十)
- PowerTip of the Day from powershell.com上周汇总(三)
- PowerTip of the Day from powershell.com上周汇总(五)
- PowerTip of the Day from powershell.com上周汇总(七)
- PowerTip of the Day-Adding Extra Information
- PowerTip of the Day-Make Function Parameters Mandatory