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
This is described in Converting a time_t Value to a File Time, which provides sample C code.
Summary:
(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
), usingstrptime()
or similar.I had been looking for something similar (converting between Windows and Linux times/epochs) and ended up writing something up using bits and pieces from MSDN and Convert Unix/Linux time to Windows FILETIME .
This naïvely replicates
gettimeofday()
from Linux using Win32.EDIT : A couple in-line comments were unclear at a second reading; updated (also added umlauts to 'i' in naïvely).
in linux you can do the following,
A unix timestamp in seconds
A date string to unixtime stamp.
Taken from https://stackoverflow.com/a/2371288/619760
Then apply the math from the aother posts to get a date value that is recognised in MS office
In office you can convert with this fomrulae which I got from the open office fourms. open office http://user.services.openoffice.org/en/forum/viewtopic.php?f=13&t=606#p2484
Take (unix time 1300973245.0592268670 / by seconds in a day (86400) ) + 25569 (days since 1899) = (40626.5607) 2011/03/24 13:27:24
Open office date is easy to figure out put 0 in a column and format it to date.
I expected this is to be the same in office 2007 but
I don't know why the 0 date is different in open office compared to windows. Now the only problem is that the time it reports is 2 years younger. Then the actual date the files were created. It should say 2009 not 2011.
This is a problem with my find command pulling date accessed instead of date created.
it should be %t and %T@ the \t are tabs.
For some reason the above formula drops two hours from the time created.
So I just add 0.08333 ( 2 hours) to the formula.