954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

COnverting date time in windows to unix timestamp

Well i want to know if there is any code for converting the date time retrived from windows system date to a unix format,
:?:

Sree007
Newbie Poster
1 post since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

If you are using perl you could use any of these perl modules

http://dates.rcbowen.com/modules/Date/

chrisranjana
Junior Poster in Training
83 posts since Jul 2005
Reputation Points: 11
Solved Threads: 3
 

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.

jitupatil_2007
Newbie Poster
13 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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.

vogu00
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

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

sushi.at
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

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.

crups
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

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...

sushi.at
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,

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.

Have a look at forum rules .
Please read before posting - http://www.daniweb.com/forums/thread78223.html

Thread Closed.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You