cls
function Ini-TimeZoneInformation($arg_TimeZone)
{
$F_TZI = [byte[]]$arg_TimeZone.GetValue("TZI")
$F_TimeZoneInformation = 1 |select bias,standardName,standardDate,standardBias,daylightName,daylightDate,daylightBias
$F_TimeZoneInformation.bias = [BitConverter]::ToInt32($F_TZI, 0)
$F_TimeZoneInformation.standardName = $arg_TimeZone.GetValue("Std")
$F_TimeZoneInformation.standardDate = ConverterTZI $F_TZI 12 "standardDate"
$F_TimeZoneInformation.standardBias = [BitConverter]::ToInt32($F_TZI, 4)
$F_TimeZoneInformation.daylightName = $arg_TimeZone.GetValue("Dlt")
$F_TimeZoneInformation.daylightDate = ConverterTZI $F_TZI 28 "daylightDate"
$F_TimeZoneInformation.daylightBias = [BitConverter]::ToInt32($F_TZI, 8)
return $F_TimeZoneInformation
}
function Ini-DynamicTimeZoneInformation($arg_Year,$arg_TimeZoneInformation)
{
$F_TimeZone = $TimeZones.OpenSubKey($arg_TimeZoneInformation.standardName)
$F_DynamicTimeZone = $F_TimeZone.OpenSubKey("Dynamic DST")
if( [array]::IndexOf($F_DynamicTimeZone.GetValueNames(),$arg_Year) -ne -1)
{
$F_TZI = [Byte[]]$F_DynamicTimeZone.GetValue($arg_Year)
$F_TimeZoneInformation = 1 |select bias,standardName,standardDate,standardBias,daylightName,daylightDate,daylightBias
$F_TimeZoneInformation.bias = [BitConverter]::ToInt32($F_TZI, 0)
$F_TimeZoneInformation.standardName = $arg_TimeZoneInformation.standardName
$F_TimeZoneInformation.standardDate = ConverterTZI $F_TZI 12 "standardDate"
$F_TimeZoneInformation.standardBias = [BitConverter]::ToInt32($F_TZI, 4)
$F_TimeZoneInformation.daylightName = $arg_TimeZoneInformation.daylightName
$F_TimeZoneInformation.daylightDate = ConverterTZI $F_TZI 28 "daylightDate"
$F_TimeZoneInformation.daylightBias = [BitConverter]::ToInt32($F_TZI, 8)
}
return $F_TimeZoneInformation
}
function Get-TimeZoneInformation($arg_Id = "All")
{
$F_TimeZoneInformations =@()
if($arg_Id -ne "All")
{
$F_TimeZone = $TimeZones.OpenSubKey($arg_Id)
$F_TimeZoneInformations += Ini-TimeZoneInformation $F_TimeZone
}
else
{
foreach($item in $TimeZones.GetSubKeyNames())
{
$F_TimeZone = $TimeZones.OpenSubKey($item)
$F_TimeZoneInformations += Ini-TimeZoneInformation $F_TimeZone
}
}
return $F_TimeZoneInformations
}
$TimeZones =Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones"
Get-TimeZoneInformation "Eastern Standard Time"
function GetDaylightChanges($arg_year,$arg_TimeZoneInformation)
{
$F_DynamicTimeZoneInformation = Ini-DynamicTimeZoneInformation $arg_year $arg_TimeZoneInformation
$F_RealTimeZoneInformation = $arg_TimeZoneInformation
if($F_DynamicTimeZoneInformation -ne $null)
{
if($F_DynamicTimeZoneInformation.GetValueNames().contions($arg_year))
{
$F_RealTimeZoneInformation = $F_DynamicTimeZoneInformation
}
}
function TimeConvert($arg_SYSTEMTIME)
{
if($arg_SYSTEMTIME.wYear -eq 0)
{
$F_Year = $arg_year
$F_Month = $arg_SYSTEMTIME.wMonth
if($arg_SYSTEMTIME.wDay -eq 5)
{
$F_DaysInMonth = [datetime]::DaysInMonth($F_Year,$F_Month)
$F_DaysOfWeek = [int](New-Object -TypeName "system.DateTime" @($F_Year,$F_Month,$F_DaysInMonth)).DayOfWeek
if ($arg_SYSTEMTIME.wDayOfWeek -ge $F_DaysOfWeek)
{
$F_Day = $F_DaysInMonth -7 +($arg_SYSTEMTIME.wDayOfWeek - $F_DaysOfWeek)
}
else
{
$F_Day = $F_DaysInMonth +($arg_SYSTEMTIME.wDayOfWeek - $F_DaysOfWeek)
}
}
else
{
$F_Day = $arg_SYSTEMTIME.wDay*7 + $arg_SYSTEMTIME.wDayOfWeek
}
$F_Hour = $arg_SYSTEMTIME.wHour
$F_Minute = $arg_SYSTEMTIME.wMinute
$F_Second= $arg_SYSTEMTIME.wSecond
$F_Milliseconds = $arg_SYSTEMTIME.wMilliseconds
return New-Object -TypeName "system.DateTime" -ArgumentList @($arg_year,$F_Month,$F_Day ,$F_Hour ,$F_Minute ,$F_Second ,$F_Milliseconds, [DateTimeKind]::Local)
}
else
{
return New-Object datatime @($F_RealTimeZoneInformation.daylightDate.wYear,$F_RealTimeZoneInformation.daylightDate.wMonth, $F_RealTimeZoneInformation.daylightDate.wDay, $F_RealTimeZoneInformation.daylightDate.wHour, $F_RealTimeZoneInformation.daylightDate.wMinute, $F_RealTimeZoneInformation.daylightDate.wSecond, $F_RealTimeZoneInformation.daylightDate.wMilliseconds, [DateTimeKind]::Local)
}
}
if($F_RealTimeZoneInformation.daylightDate.wMonth -ne 0)
{
$F_StartDate = TimeConvert $F_RealTimeZoneInformation.daylightDate
}
else
{
$F_StartDate = [datetime]::MinValue
}
if($F_RealTimeZoneInformation.standardDate.wMonth -ne 0)
{
$F_EndDate = TimeConvert $F_RealTimeZoneInformation.standardDate
}
else
{
$F_EndDate = [datetime]::MinValue
}
New-Object -TypeName "System.Globalization.DaylightTime" @($F_StartDate,$F_EndDate, (New-Object "system.TimeSpan" @(0,0,0)))
}
GetDaylightChanges 2010 (Get-TimeZoneInformation "Eastern Standard Time")