Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC - Is local time in Razor View calculated on the Client or server?

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

like image 886
JP. Avatar asked Dec 20 '22 18:12

JP.


1 Answers

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.

like image 197
rossipedia Avatar answered Jan 01 '23 13:01

rossipedia