Powershell: get-date & [datetime] :: FromFileTime returns different values

Why do get-date and [datetime] :: FromFileTime return different values ​​when converting FileTime? Example:

Get-Date 129442497539436142 

returns on Thursday, March 10, 0411 4:55:53 but

 [datetime]::FromFileTime("129442497539436142") 

coming back Thursday, March 10, 2011 11:55:53

+4
source share
4 answers

They give me the same result, apparently because I am in GMT.

(FromFileTime parses time as UTC , Get-Date seems to use your local time.)

+5
source

TIP: I am on average GMT, and I get the same result.

 PS > Get-Date 129442497539436142 10 March 0411 16:55:53 PS > [datetime]::FromFileTime("129442497539436142") 10 March 2011 16:55:53 
+3
source

FileTimes are the so-called Ticks. 10 million pass every second. File time: 0 at midnight, January 1, 1601 (UTC).

Get-date also has ticks, but the tick base used by Get-Date is not 1601.
This is January 1st. 1.
You can basically identify 2 different types of ticks by the first digit.

Fixing files starts with the number 1 in the range from -100 to +200 years.

Ticks using the base on January 1, 0 start at 6 in about the same time range ...

In PowerShell, you can get confirmation. 1st year 1 is the 0 mark by typing:

 [datetime]'0001-01-01' | Select-Object -property Ticks 
0
source

It is based on your local "long dates" format.

enter image description here

Or you should change your "Long Date" system

(OR) Use the command below

(Get-Date) .ToString ("dd / mm / yyyy")

enter image description here

https://technet.microsoft.com/en-us/library/ee692801.aspx

Regards, Manikandan Boopathy

0
source

Source: https://habr.com/ru/post/1343641/


All Articles