批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[转载代码] [PowerShell每日技巧]判断日期是否合法(20140204)

If you need to test whether some information resembles a valid date format, here is a test function:
  1. function Test-Date
  2. {
  3.     param
  4.     (
  5.         [Parameter(Mandatory=$true]
  6.         $Date
  7.     )
  8.     (($Date -as [DateTime]) -ne $null)
  9. }
复制代码
It uses the -as operator to try and convert the input to a DateTime format. If this fails, the result is $null, so the function checks for this and returns $true or $false. Note that the -as operator uses your local DateTime format.

http://powershell.com/cs/blogs/tips/archive/2014/02/04/testing-for-valid-date.aspx

返回列表