Skip to content

Instantly share code, notes, and snippets.

@gravejester
Created May 3, 2015 15:05
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 gravejester/3032ca86732f06f48a88 to your computer and use it in GitHub Desktop.
Save gravejester/3032ca86732f06f48a88 to your computer and use it in GitHub Desktop.
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