PowerTip: Use UNIX Date Formatting in PowerShell

PowerTip: Use UNIX Date Formatting in PowerShell

Rate This
  • Comments 2

Summary:  Learn how to use UNIX date formatting in Windows PowerShell.

Hey, Scripting Guy! Question How can I use my prior knowledge of UNIX date formatting to specify dates in Windows PowerShell?

Hey, Scripting Guy! AnswerUse the Get-Date cmdlet and the –Uformat parameter. For example, to display a date in standard format for your current locale, use the “x” format specifier:

PS C:\> Get-Date -UFormat %x

03/11/13 

Leave a Comment
  • Please add 2 and 3 and type the answer here:
  • Post
  • %s being the switch to convert to epoch time. Then...

    Get-date $(Get-Date("10/07/1975 08:00")) -uFormat %s

    to get a given date in epoch time, and the following function to convert back to date time in local time zone.

    Function Get-DateFromEpoch ($EpochDate) {

       [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($EpochDate))

    }

    Get-DateFromEpoch("174211200")

    Thursday, 10 July 1975 4:00:00 PM

  • Get the Epoch: www.coolepochcountdown.com

Page 1 of 1 (2 items)