0

I use the code below to get the filestamps of a file

Get-ChildItem "%FullPathOfFileToGetTimestampFor%"  -Force | Select-Object FullName, CreationTime, LastAccessTime, LastWriteTime, Mode, Length

The variable "%FullPathOfFileToGetTimestampFor%" is replaced with the path of the file to get the timestamps from

However, because the default language of the system is not English, instead of "a.m." or "p.m." I get symbols at the end of the date/time (e.g. 2/11/2021 7:03:42 §£).

I would like to get those timestamps in a 24 hour format (e.g.yyyy-MM-dd hh:mm:ss, 2021-11-02 19:03:42)

Thank you

coreto98
  • 17
  • 6
  • 1
    A DateTime object like `LastWriteTime` can be formatted any way you want, for instance by changing it to your needs using a calculated property. Another way would be to set your session to a different culture before your code line an afterwards set it to what it was. See [this question](https://stackoverflow.com/q/2379514/9898643) – Theo Nov 18 '21 at 21:24

2 Answers2

0

Try using Select-Object CreationTimeUtc (instead of CreationTime).

cgranier
  • 130
  • 2
  • 8
0

A [datetime] can be formatted. To get an ISO-8601 formatted date use:

PS C:\> Get-Date -Format 's'
2021-11-18T15:36:29

A commonly used format is:

PS C:\> Get-Date -Format 'yyyy-MM-dd hh:mm:ss'
2021-11-18 03:36:33
lit
  • 14,456
  • 10
  • 65
  • 119