Saturday, 28 August 2010

Get-TimeZoneInfoInfo

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays/Uses TimeZoneInfo properties  
  4. .DESCRIPTION 
  5.     This script displays the use of all the TimeZoneInfo Properties. 
  6. .NOTES 
  7.     File Name  : Get-TimeZoneInfoInfo.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://pshscripts.blogspot.com/2010/08/get-timezoneinfoinfo.html 
  13.     MSDN Sample posted at: 
  14.         http://msdn.microsoft.com/en-us/library/system.timezoneinfo_properties.aspx    
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .Get-TimeZoneInfoInfo.ps1' 
  17.     Time Zone: (GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London 
  18.       Time zone is 0 hours 0 minutes later than Coordinated Universal Time. 
  19.       Current time is 12:22 PM on 8/28/2010 GMT Daylight Time 
  20.       Timezone id              : GMT Standard Time 
  21.       Supports Daylight Saving : True 
  22.       Daylight Saving Zone Name: GMT Daylight Time 
  23.   
  24.     Time Zone: (GMT+04:30) Kabul 
  25.       Time zone is 4 hours 30 minutes later than Coordinated Universal Time. 
  26.       Current time is 12:22 PM on 8/28/2010 Afghanistan Standard Time 
  27.       Timezone id              : Afghanistan Standard Time 
  28.       Supports Daylight Saving : False 
  29.       Daylight Saving Zone Name: Afghanistan Daylight Time 
  30.   
  31.     Time Zone: UTC 
  32.       Time zone is 0 hours 0 minutes later than Coordinated Universal Time. 
  33.       Current time is 12:22 PM on 8/28/2010 UTC 
  34.       Timezone id              : UTC 
  35.       Supports Daylight Saving : False 
  36.       Daylight Saving Zone Name: UTC 
  37. #> 
  38. # Display Information About Time Zones 
  39.  
  40. # Get current date 
  41. $Datenow = Get-Date 
  42.  
  43. # Display info re Local Time Zone 
  44. $LocalZone = [System.TimeZoneInfo]::Local 
  45. $t1 = [system.Math]::Abs($LocalZone.BaseUtcOffset.Hours) 
  46. $t2 = [System.Math]::Abs($LocalZone.BaseUtcOffset.Minutes)  
  47. $t3 = if ($LocalZone.BaseUtcOffset -ge  [System.Timespan]::Zero) {"later"} else {"earlier"
  48. $t4 = if ($LocalZone.IsdaylightSavingTime($datenow)) {$Localzone.DaylightName} else {$Localzone.Standardname} 
  49. "Time Zone: {0}" -f $Localzone.Displayname 
  50. "  Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f   $t1,$t2, $t3 
  51. "  Current time is {0:t} on {0:d} {1}" -f $datenow,$t4 
  52. "  Timezone id              : {0}" -f $LocalZone.Id 
  53. "  Supports Daylight Saving : {0}" -f $LocalZone.SupportsDaylightSavingTime 
  54. "  Daylight Saving Zone Name: {0}" -f $Localzone.DaylightName 
  55. "" 
  56.  
  57. # Get Kabul Time 
  58. $Kt = [system.TimeZoneInfo]::GetSystemTimeZones()  | ? {$_.id -match "Afghanistan Standard Time"
  59. $tz = $kt.Displayname 
  60. $t1 = [system.Math]::Abs($kt.BaseUtcOffset.Hours) 
  61. $t2 = [System.Math]::Abs($kt.BaseUtcOffset.Minutes)  
  62. $t3 = if ($kt.BaseUtcOffset -ge  [System.timespan]::Zero) {"later"} else {"earlier"
  63. $t4 = if ($Kt.IsdaylightSavingTime($datenow)) {$Kt.DaylightName} else {$Kt.Standardname} 
  64.  
  65. # Display information 
  66. "Time Zone: {0}" -f $Kt.Displayname 
  67. "  Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f   $t1,$t2,$t3 
  68. "  Current time is {0:t} on {0:d} {1}" -f $datenow,$t4 
  69. "  Timezone id              : {0}" -f $Kt.Id 
  70. "  Supports Daylight Saving : {0}" -f $Kt.SupportsDaylightSavingTime 
  71. "  Daylight Saving Zone Name: {0}" -f $Kt.DaylightName 
  72. "" 
  73.  
  74. # Display Information regarding UTC 
  75. $UtcZone = [System.TimeZoneInfo]::UTC 
  76. $t1 = [system.Math]::Abs($UtcZone.BaseUtcOffset.Hours) 
  77. $t2 = [System.Math]::Abs($UtcZone.BaseUtcOffset.Minutes)  
  78. $t3 = if ($UtcZone.BaseUtcOffset -ge  [System.Timespan]::Zero) {"later"} else {"earlier"
  79. $t4 = if ($UtcZone.IsdaylightSavingTime($datenow)) {$Utczone.DaylightName} else {$UtcZone.Standardname} 
  80.  
  81. # Display information 
  82. "Time Zone: {0}" -f $UtcZone.Displayname 
  83. "  Time zone is {0} hours {1} minutes {2} than Coordinated Universal Time." -f   $t1,$t2,$t3 
  84. "  Current time is {0:t} on {0:d} {1}" -f $Datenow,$t4 
  85. "  Timezone id              : {0}" -f $UtcZone.Id 
  86. "  Supports Daylight Saving : {0}" -f $UtcZone.SupportsDaylightSavingTime 
  87. "  Daylight Saving Zone Name: {0}" -f $UtcZone.DaylightName 

No comments: