Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways to Convert Unix/Linux time to Windows time

I want many ways to convert between the two on both systems. I am looking for a quick and easy way to do this.

I would like Python ways, excel, openoffice calc ways, access ways, command line ways. Any other way that you do it would be nice as well. Going the other way (from Windows to Linux) would also be nice

I have output from some of my scripts that include the time in seconds since 1970, but I want to convert to Windows time. So that when it gets imported into a database it does not mess up the times.

In Linux you can obtain time in microseconds (10^-6 sec) from 1 Jan 1970 using gettimeofday.

In Windows Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).

Here is a C way. Convert Unix/Linux time to Windows FILETIME

Example out put from find

find ./sd-mmc-card/ -iname *.jpg -printf "%h/%f\t%f\t%a\t%Ax\t%AT\t%A@\n" > dbtime.txt

./sd-mmc-card/0117.jpg    0117.jpg    Thu Mar 24 15:27:25.0059226867 2011    24/03/2011    15:27:25.0592268670    1300973245.0592268670
like image 746
nelaaro Avatar asked Dec 12 '22 14:12

nelaaro


1 Answers

This is described in Converting a time_t Value to a File Time, which provides sample C code.

Summary:

filetime = (unixtime * 10000000) + 116444736000000000

0x3DE43B0C → 0x01C295C4:91150E00 (2002-11-27 03:25:00 +0000)

(Also helpful is How to recognize different types of timestamps from quite a long way away.)


Often it is easier to parse the human-readable timestamp, such as "2002-11-27 03:25:00" (printf %AF %AT), using strptime() or similar.

like image 54
user1686 Avatar answered Dec 26 '22 00:12

user1686