• Alaknár@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      1
      ·
      20 minutes 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.