Skip to content

Instantly share code, notes, and snippets.

@yvanin
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yvanin/ca333332bc63929e4e87 to your computer and use it in GitHub Desktop.
Save yvanin/ca333332bc63929e4e87 to your computer and use it in GitHub Desktop.
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