I'm building an ASP.NET Core MVC app that shows data from an API, including UTC timestamps. I want each user to see times in their local timezone, but since the server doesn't know the user's timezone, I'm unsure how to handle it—should I convert times in JavaScript on the client side, or send the user's timezone to the server? What's the best practice for this, and how can I implement it in Razor or a controller?
Loading

Tasadduq BurneyPosted Dec 8, 2025, 5:50 PM
Hey,
Hope you're keeping well.
The cleanest approach is to detect the user's timezone in JavaScript using
Intl.DateTimeFormat().resolvedOptions().timeZoneand send it to the server via a cookie or AJAX so your ASP.NET Core controller can convert usingTimeZoneInfo.ConvertTimeFromUtc. This keeps all formatting consistent and allows you to handle DST correctly with .NET’s timezone database or NodaTime. Doing conversion entirely client-side is fine for display-only scenarios, but server-side conversion ensures accurate timestamps in Razor views, APIs, and exports. In MVC, store the converted value in your ViewModel before rendering, so your views remain free of conversion logic.Thanks and regards,
Taz