Getting BlogEngine.NET To Work With The Local Time Zones: Part II (in case JavaScript is disabled)

In the article called "Getting BlogEngine.NET To Work With The Local Time Zones"I described how to convert the times of the posts to the local time zones of users relying solely on JavaScript. However I got a complaint that if JavaScript is disabled for some reasons, then no date and time are displayed.

It can be fixed, I’ll explain how, but in this case – if JavaScript is disabled, the time will be in GMT, so just put the following code to PostView.ascx that basically outputs the time in GMT and if JavaScript is enabled it replaces a GMT time with a local time.

<span id="postDate_<%=Post.Id %>" class="pubDate">
  on     <%=Post.DateCreated.ToLongDateString() + " " +
  Post.DateCreated.ToShortTimeString() %> GMT
<script type="text/javascript">
  $("postDate_<%=Post.Id %>").firstChild.nodeValue =
    "on " +
      '<%=Post.DateCreated.ToLongDateString() + " " + Post.DateCreated.ToShortTimeString() %>'
Mike Borozdin (Twitter)
27 June 2008

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. My personal thoughts tend to change, hence the articles in this blog might not provide an accurate reflection of my present standpoint.

© Mike Borozdin