Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function ConvertTo-DateTime {
<#
.SYNOPSIS
Converts a TimeZoneInfo object into a DateTime object for that time zone.
.DESCRIPTION
This function can be used to convert a specific time zone into a DateTime object
for that time zone.
.EXAMPLE
Get-TimeZone | Where-Object {$_.DisplayName -like '*Sydney*'} | ConvertTo-DateTime
.NOTES
Author: Øyvind Kallstad
Date: 03.05.2015
Version: 1.0
#>
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[TimeZoneInfo] $TimeZone
)
$dateTime = ([datetime]::Now)
$dtOffset = $TimeZone.GetUtcOffset($dateTime)
Write-Output (($dateTime.Add($dtOffset)).ToUniversalTime())
}
function Get-TimeZone {
Write-Output ([System.TimeZoneInfo]::GetSystemTimeZones())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment