Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
My CPU show US Eastern Time correctly. However, in my .Net program, I use DateTime.Now shows the time is 4 hours behind (e.g. 7:55am in my CPU's right-bottom, 3:55am in my program). How can it be adjusted? Thanks.
Posted
Comments
Mayank Vashishtha 12-Aug-14 8:26am    
Why dont you use System.DateTime.UtcNow, It will give you time in UTC, then you can convert it into the time zone of the user.

1 solution

Current timezone is cached and sometimes hiccups like yours can occur. You have probably meddled with timezone or have manually adjusted time to +/- several hours.
You'll need to call System.Globalization.CultureInfo.ClearCachedData() method to clear cached value.
 
Share this answer
 
Comments
s yu 12-Aug-14 8:58am    
Problem found to be the conversion from Unix Time Stamp to dateTime
row["Date_Time"] = (UnixTimeStampToDateTime(Convert.ToDouble(eTime))).ToString();
Revised the code as
row["Date_Time"] = DateTime.Now.ToLocalTime();
Thanks.

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