Skip to content

Instantly share code, notes, and snippets.

@yvanin
Last active August 29, 2015 14:24
ASP.NET MVC Html helper for showing a UTC date from a server in the timezone of a browser
public static MvcHtmlString LocalDateTime(this HtmlHelper helper, DateTime utcDateTime)
{
return new MvcHtmlString(
String.Format(
"<script>var d=new Date('{0}');document.write(new Date(d.getTime()-d.getTimezoneOffset()*60000))</script>",
utcDateTime.ToString("g")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment