cm0002@lemmy.world to Programmer Humor@programming.dev · 2 days agoI'm new to using Ruby and this tickled me pinklemmy.mlimagemessage-square64fedilinkarrow-up1453arrow-down15cross-posted to: programmerhumor@lemmy.ml
arrow-up1448arrow-down1imageI'm new to using Ruby and this tickled me pinklemmy.mlcm0002@lemmy.world to Programmer Humor@programming.dev · 2 days agomessage-square64fedilinkcross-posted to: programmerhumor@lemmy.ml
minus-squareraman_klogius@ani.sociallinkfedilinkEnglisharrow-up3·9 hours agoObligatory Tom Scott video
minus-squareAlaknár@sopuli.xyzlinkfedilinkEnglisharrow-up1·2 hours agoThis 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.
Obligatory Tom Scott video
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:
And you get a DateTimeOffset object, which is this beauty:
DateTime
is the time in your target timezone,UtcDateTime
is, well, the UTC time, andLocalDateTime
is the time on host you ran the commands on.