UNIX time to DateList

Since Mathematica version 10.1 there is the function FromUnixTime that performs the conversion from a UNIX timestamp to a DateObject.

FromUnixTime[1427793986]

enter image description here

FromUnixTime[1427793986] // DateList

{2015, 3, 31, 11, 26, 26.}

FromUnixTime[0, TimeZone -> 0]

enter image description here


The number of seconds between January 1, 1900 and January 1, 1970 can be given by AbsoluteTime[{1970, 1, 1, 2, 0, 0}]. There is also DateList which, if given a number, will calculate what the date would be if that was the number of seconds given by AbsoluteTime.

DateList[AbsoluteTime[], TimeZone -> 2]

{2013, 8, 26, 2, 28, 7.97767}

DateList[AbsoluteTime[{1970, 1, 1, 2, 0, 0}] + First@ReadList["!date +%s"]]

{2013, 8, 26, 2, 28, 7.}

The slight difference seems to be because the UNIX timestamp rounds downwards.

(First@ReadList["!date +%s"] only gives the current timestamp on UNIX systems. Everyone else will have to paste in their own timestamps to try it out. Also, I'm using my own time zone which is +2.)