Last active
September 3, 2020 13:55
-
-
Save MattMS/bd2811017bd45aa6b8593759070d9ff7 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 Global:Get-Now { | |
$CI = New-Object System.Globalization.CultureInfo("en-AU") | |
$Epoch = [DateTimeOffset]::UnixEpoch | |
$Now = [DateTimeOffset]::Now | |
$UnixDay = ($Now.UtcDateTime - $Epoch.UtcDateTime).Days | |
$UnixDaySecond = [int]$Now.UtcDateTime.TimeOfDay.TotalSeconds | |
$UnixSecond = $Now.ToUnixTimeSeconds() | |
[PSCustomObject]@{ | |
DayOfYear = $Now.DayOfYear | |
Global = $Now.UtcDateTime | |
GlobalWeek = $CI.Calendar.GetWeekOfYear($Now.UtcDateTime, $CI.DateTimeFormat.CalendarWeekRule, $CI.DateTimeFormat.FirstDayOfWeek) | |
Local = $Now.LocalDateTime | |
LocalWeek = $CI.Calendar.GetWeekOfYear($Now.LocalDateTime, $CI.DateTimeFormat.CalendarWeekRule, $CI.DateTimeFormat.FirstDayOfWeek) | |
Offset = $Now.Offset | |
UnixDay = $UnixDay | |
UnixDayHex = $UnixDay.ToString("X") | |
UnixDaySecond = $UnixDaySecond | |
UnixDaySecondHex = $UnixDaySecond.ToString("X") # This can get to 5 characters (max is 0x15180) | |
UnixSecond = $UnixSecond | |
UnixSecondHex = $UnixSecond.ToString("X") | |
}} | |
Set-Alias -Name now -Value Global:Get-Now | |
$Env:SecondsInDay = 60 * 60 * 24 | |
$Env:SecondsInYear = 60 * 60 * 24 * 365 # Only useful as rough guide (since it ignores leap years) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment