Monday 19 January 2009

Get-LeapYear.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates use of System.Datetime to determine leap year  
  4. .DESCRIPTION 
  5.     This script creates four date objects and checks to see if 
  6.     the date is a leap year. The last object is today's date.  
  7. .NOTES 
  8.     File Name  : Get-LeapYear.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11. .LINK 
  12.     http://www.pshscripts.blogspot.com 
  13. .EXAMPLE 
  14.     PS c:\foo> .\Get-LeapYear.ps1 
  15.     2000 is a leap year: True 
  16.     2002 is a leap year: False 
  17.     2004 is a leap year: True 
  18.     2009 is a leap year: False 
  19. #> 
  20.  
  21. ## 
  22. #  Start of script 
  23. ## 
  24.  
  25. # Create three specific date objects, plus today 
  26. $d1 = [system.datetime]  "Jan 1 2000" 
  27. $d2 = [System.datetime]  "Jan 1 2002" 
  28. $d3 = [System.datetime]  "Jan 1 2004" 
  29. $d4 = get-date 
  30.  
  31. # Are they leap years?
  32. "{0} is a leap year: {1}" -f $d1.year,([system.datetime]::isleapyear($d1.year)) 
  33. "{0} is a leap year: {1}" -f $d2.year,([system.datetime]::isleapyear($d2.year)) 
  34. "{0} is a leap year: {1}" -f $d3.year,([system.datetime]::isleapyear($d3.year)) 
  35. "{0} is a leap year: {1}" -f $d4.year,([system.datetime]::isleapyear($d4.year)) 
  36. # End Script 

No comments: