this post was submitted on 24 Aug 2025
456 points (98.9% liked)

Programmer Humor

25958 readers
903 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] raman_klogius@ani.social 3 points 17 hours ago (1 children)
[โ€“] Alaknar@sopuli.xyz 1 points 10 hours ago

This is exactly why I love PowerShell.

Need the [DateTime] object from 10 years ago? No biggie, just chuck (Get-Date).AddYears(-10) down your console.

Need it in a specific timezone? That one's trickier, but since PowerShell can do .Net, run this:

$TargetDateTime = (Get-Date).AddYears(-10)
$TargetTimeZone = "India Standard Time"
$tz = [TimeZoneInfo]::FindSystemTimeZoneById($TargetTimeZone)
$utcOffset = $tz.GetUtcOffset($TargetDateTime)
[DateTimeOffset]::new($TargetDateTime.Ticks, $utcOffset)

And you get a DateTimeOffset object, which is this beauty:

DateTime           : 25/08/2015 23:15:14
UtcDateTime        : 25/08/2015 17:45:14
LocalDateTime      : 25/08/2015 19:45:14
Date               : 25/08/2015 00:00:00
Day                : 25
DayOfWeek          : Tuesday
DayOfYear          : 237
Hour               : 23
Millisecond        : 421
Microsecond        : 428
Nanosecond         : 600
Minute             : 15
Month              : 8
Offset             : 05:30:00
TotalOffsetMinutes : 330
Second             : 14
Ticks              : 635761413144214286
UtcTicks           : 635761215144214286
TimeOfDay          : 23:15:14.4214286
Year               : 2015

DateTime is the time in your target timezone, UtcDateTime is, well, the UTC time, and LocalDateTime is the time on host you ran the commands on.