Last active
August 29, 2015 14:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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