开发者

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.

For example, user chooses 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.

What should I do? Reset date timezone on client side? Add offset on server? Anything else?


I think you should do:

date.getTime() + (date.getTimezoneOffset() * 60 * 1000)

This will "remove" the offset for the user timezone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜