Skip to content

Instantly share code, notes, and snippets.

@rchaganti
Last active March 20, 2023 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rchaganti/9055e80c1995e112945c07c43e3be33d to your computer and use it in GitHub Desktop.
Save rchaganti/9055e80c1995e112945c07c43e3be33d to your computer and use it in GitHub Desktop.
tzDiff.ps1
param
(
[Parameter(Mandatory = $true)]
[String[]]
$Timezone,
[Parameter()]
[Datetime]
$Target
)
if (!$Target)
{
# Get the local time as the target
$Target = Get-Date
}
$tzObject = [System.Collections.Arraylist]::new()
$tzObject.Add(
[PSCustomObject]@{
'Timezone' = 'Local'
'Time' = $Target
'DifferenceInHours' = 0
}
) | Out-Null
foreach ($tz in $Timezone)
{
# Get the timezone difference
$localTz = [System.TimeZoneInfo]::Local
$remoteTz = [System.TimeZoneInfo]::FindSystemTimeZoneById($tz)
$tzDifference = [float]($remoteTz.BaseUtcOffset.TotalHours - $localTz.BaseUtcOffset.TotalHours)
$remoteTime = [System.TimeZoneInfo]::ConvertTime($Target, $localTz, $remoteTz)
$tzObject.Add(
[PSCustomObject]@{
'Timezone' = $tz
'Time' = $remoteTime
'DifferenceInHours' = $tzDifference
}
) | Out-Null
}
return $tzObject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment