Operate with date timezone
I have Date
on client side (user choose it in date picker) and I want to send it to server and use UTC value for future calculations.
Tue Oct 04 2011 00:00:00 GMT+0300 (E. Europe Daylight Time)
, I send millise开发者_C百科conds to server using date.getTime()
. On server I use method:
public static DateTime GetDateByMilliseconds(long milliseconds)
{
var date = new DateTime(1970, 1, 1);
return date.AddMilliseconds(milliseconds);
}
And get Oct 03, 2011 09:00:00 PM
. But I want to operate with value Oct 04 2011 00:00:00
.
I think you should do:
date.getTime() + (date.getTimezoneOffset() * 60 * 1000)
This will "remove" the offset for the user timezone.
精彩评论