This may be a stupid question, but when I write the following in my razor view in ASP.NET MVC 3 is the local time calculated on the client or the server?
@Html.LabelFor(x=>x.MyDate.ToLocalTime())
I'd imagine it is the server-side, since the view is assembled on the server before sending it back to the client, but I'm not entirely confident.
Thanks
JP
This is server side. Your Razor views are executed on the server, thus all DateTime.ToLocalTime() methods are evaluated on the server using the server's time zone.
If you need it to evaluate in the context of the client, then you'll need some way to allow the client to supply its time zone information, and then use the TimeZoneInfo
and TimeZone
classes to work with that time zone, probably using TimeZone.ToLocalTime()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With