开发者

Fetch client timezone from javascript and instantiate in asp.net

I send client's timezone us开发者_如何学编程ing javascript,

new Date().getTimezoneOffset()/60

What is sent to SERVER is a string of sort "+5:30". Now, my question is how to instantiate corresponding TimeZone instance in Managed/server code using this Offset received from client.


DateTime time;
var success = DateTime.TryParse("2011-07-11 11:11:11+0530", out time);

Basically, you can use DateTime.TryParse to parse a standardised timestamp into a proper DateTime. The TryParse will return true on success, false if there's something wrong, and the time variable will contain your parsed DateTime on success.

The +0530 is the timezone offset from UTC in hours and minutes.


You can create a custom TimeZoneInfo in the following way

TimeZoneInfo tinfo = TimeZoneInfo.CreateCustomTimeZone("IST", TimeSpan.Parse("5:30"), "Std Time", "Display Name");

Then you could use something like this to convert to the destination zone

TimeZoneInfo.ConvertTime(dt,tinfo)

I presume you were looking for something on these lines, else please edit the post further

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜