Click here to Skip to main content
15,914,014 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

i just converted DateTime.Now.Date.ToFileTime() but when converting back to datetime from FileTime it gives some different datetime.

Please help me to fix this issue,i have to do this conversion for my US client (EST timezone)

Below is the time of US when converting FileTime value to actual datetime it gives some difference in hours.

VB
08/18/2015 09:55:02
FileTime :  130843440000000000



Thanks
Jeetendra
Posted
Comments
Sergey Alexandrovich Kryukov 18-Aug-15 9:58am    
How did you do it?
—SA

1 solution

You're not getting the same time back because you've stripped out the time part by calling DateTime.Now.Date.

The Date property[^] returns "a new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00)."

(NB: Because you're running this on a computer in the EST timezone, this will actually be equivalent to 4 AM UTC.)

If you want to include the time, then don't use the Date property:
C#
long fileTime = DateTime.Now.ToFileTime();
DateTime theTime = DateTime.FromFileTime(fileTime);
 
Share this answer
 
v2

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