Created
May 3, 2015 15:05
-
-
Save gravejester/3032ca86732f06f48a88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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