C#/ ASP.NET MVC3,从DateTime.UtcNow转换,到客户端的时区。如何获得时区信息? [英] C#/ASP.NET MVC3, convert from DateTime.UtcNow, to client's timezone. How to get timezone info?

查看:164
本文介绍了C#/ ASP.NET MVC3,从DateTime.UtcNow转换,到客户端的时区。如何获得时区信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储日期为UTC,通过插入新记录时调用DateTime.UtcNow。我想在该日期访问者的时区转换。

I store dates as UTC, by calling DateTime.UtcNow when inserting new records. I want to convert that date to the visitor's timezone.

有上的TimeZoneInfo一个方法来做到这一点:

There's a method on TimeZoneInfo to do it:

public static DateTime ConvertTimeFromUtc(
    DateTime dateTime,
    TimeZoneInfo destinationTimeZone
)

但我在哪里可以拉的TimeZoneInfo destinationTimeZone 从在asp.net MVC3?它是在请求对象提供可靠?

but where can I pull TimeZoneInfo destinationTimeZone from, in asp.net mvc3? Is it reliably available in the request object?

推荐答案

遗憾的是没有那么简单正如人们所期望。
Request对象不会给你所需要的信息。
您将需要使用JavaScript。
这里是一个很好的实现:
<一href=\"http://weblogs.asp.net/cprieto/archive/2010/01/03/handling-timezone-information-in-asp-net.aspx\" rel=\"nofollow\">http://weblogs.asp.net/cprieto/archive/2010/01/03/handling-timezone-information-in-asp-net.aspx

Unfortunately it is not as straightforward as one would expect. The Request object will not give you the info you require. You will need to use javascript. Here is a good implementation: http://weblogs.asp.net/cprieto/archive/2010/01/03/handling-timezone-information-in-asp-net.aspx

这篇关于C#/ ASP.NET MVC3,从DateTime.UtcNow转换,到客户端的时区。如何获得时区信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆