In my application i receive Time stamp and in c# code I convert into date and pass this date to execute the stored procedure .My application is placed in server machine. But when this date is printed in log i saw the date is receiving in server one day less. Below is my code to convert from time stamp to date,
DateTime fromDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
fromDate =fromDate.AddMilliseconds(1430159400000).ToLocalTime();
date is : '2015-04-28' But when in server it receive as '2015-04-27'. This i came to know when i print this date in log. What i am doing wrong here!. Any suggessions most welcome.
Regards Sangeetha
Well currently you're converting the UTC timestamp to the system-local time - and presumably your server is in a different time zone to you.
I would strongly advise you to log the UTC timestamp directly, in UTC. Whatever reads your logs can then convert it to a local time in whatever time zone you want, but it's a lot more portable that way:
So, you should:
ToLocalTime
callZ
at the end, so that it's clear it's in UTC.If you're storing timestamps in the database, I'd recommend storing those in UTC as well. Some kinds of date/time values are best stored in local time, but timestamps are more global, representing an instant in time, so UTC is a suitable zone to use for storage.
See more on this question at Stackoverflow