Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi I want to write a program which have to convert the last written time of a file to a timestamp.
But the result is wrong:
Time: 24.10.2010 13:23:27 (Days, Month, Year Hours,Minutes,Seconds)
Timestamp: 1287926608

But this Timestamp is for 24.10.2010 15:23:28 and this is wrong.
Maby you have a better solution because I want to compare the date of a ftp online file and of a offline file.
My idea was to convert the time to a timestamp
DateTime date1 = new DateTime(1970, 1, 1);
TimeSpan ts = new TimeSpan(NextFile.LastWriteTime.Ticks - date1.Ticks);
Console.WriteLine(Convert.ToInt32(ts.TotalSeconds));



Pleas help me
Andre
(Sorry for this bad English Im from Germany)
Posted
Comments
cp.soni 29-Oct-10 9:17am    
Can u please clear me on the from where you got Timestamp:1287926608 (is it in the file ?)If so how does it get generated ?

I'm sorry...what are you expecting it to output?

Because you are telling it to output the total seconds that have elapsed between the last written time and the January 1, 1970..

Why are you messing with TimeSpans at all?

Mark was close...but date1 is just a number you picked because, I assume, you thought it was the epoch.

It's actually not in .Net. Try this:
C#
DateTime date1 = new DateTime(0);

and see what date it gives you...it will give you: Jan 1, 0001, Midnight.

If you want that type of time stamp, just try this:
C#
Console.WriteLine(NextFile.LastWriteTime.ToString("dd.MM.yyyy HH:mm:ss"));


FYI, that totalseconds = 14,906 days and 13 hours and 23 minutes and 28 seconds. The Julian Day Number for Jan 1, 1970 is 2440588 and the Day Number for Oct. 24, 2010 is 2455494 which is a difference of 14,906 days.

And if you're just trying to compare two dates you can just do
C#
if (date1 != date2)
 
Share this answer
 
v2
date1.ToString("yyyyMMddHHmmssffff");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900