asp.net-mvc - ASP.NET MVC - Razor View 中的本地时间是在客户端还是服务器上计算的?

标签 asp.net-mvc datetime utc

这可能是一个愚蠢的问题,但是当我在 ASP.NET MVC 3 的 Razor View 中编写以下内容时,本地时间是在客户端还是服务器上计算的?

@Html.LabelFor(x=>x.MyDate.ToLocalTime())

我想它是服务器端,因为 View 在发送回客户端之前在服务器上组装,但我并不完全有信心。

谢谢

J.P

最佳答案

这是服务器端。您的 Razor View 在服务器上执行,因此所有 DateTime.ToLocalTime() 方法都使用服务器的时区在服务器上进行评估。

如果您需要它在客户端的上下文中进行评估,那么您将需要某种方式来允许客户端提供其时区信息,然后使用 TimeZoneInfo TimeZone 类来处理该时区,可能使用 TimeZone.ToLocalTime() 方法.

关于asp.net-mvc - ASP.NET MVC - Razor View 中的本地时间是在客户端还是服务器上计算的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11800031/

相关文章:

sql - SQL Server 中的 DateTime2 与 DateTime

c# - 如何获得年/月/周/日中两个日期之间的差异?

Python:strftime() UTC 偏移量在 Windows 中未按预期工作

javascript - Angular Bootstrap DatePicker UTC 错误输出

Python 日期时间 : use strftime() with a timezone-aware date

.net - Umbraco 与 DotNetNuke : can't decide which one is more suitable

datetime - 流畅的 NHibernate 映射和公式/日期部分

asp.net-mvc - 在 Identity 2.0 中重定向未经授权的用户

asp.net-mvc - 防伪验证异常 : The provided anti forgery token was meant for a different claims-based user than the current user

c# - mvc 数据库的第一个问题是 edmx/relationships 和显示 id 字段的 View