Well i want to know if there is any code for converting the date time retrived from windows system date to a unix format,
hey you can try this code in C#
double epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000; Console.WriteLine(epoch.ToString());
this will help to convert current time to unix time stamp.
The offset ( 621355968000000000) is wrong. The correct offset is
const unsigned long long UnixTimeOffset = ((unsigned long long)(369 * 365 + 89) * 24 * 3600 * 10000000);
See ntfs-3g source code.
Just a tip: Disregard vogu00's message, the offset is indeed correct, using his suggested corrected value (after converting it into proper C# syntax) returns the year 3610 instead of 2010...
just another idea here: I wouldn't use a double to store the epoch value ... this is defined as a long
Nope, vogu is right. I tried it. His offset
(369 * 365 + 89) * 24 * 3600 * 10000000) = 116444736000000000
is also confirmed by Microsoft (whatever that means). See http://support.microsoft.com/kb/167296.
And in deed, the ntfs-3g uses the same value, see http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/fs/ntfs/time.h
@sushi.at: Vogu's source line is just perfect C++, no transformations needed.
Never said his code wouldn't compile in C++.... he labeled it as C# though. And when you run it in C# the offset is wrong. Seems like we got the correct offsets for both languages then...
We appreciate your help. Have you ever noticed that the current thread is four years old? Please do not resurrect old threads or solved threads.
If you want to ask question, start your own thread.
We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.