<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Dev411 Blog: Displaying Dates and Times Using JavaScript</title>
    <link>http://www.dev411.com/blog/2007/02/05/displaying-dates-and-times-using-javascript</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>John Wang on Technology</description>
    <item>
      <title>Displaying Dates and Times Using JavaScript</title>
      <description>&lt;p&gt;Some considerations when displaying dates and times on a website include showing delta times, customized timezones and caching. Often it's nice to show a delta time like "10 minutes ago" or "5 days ago" to give readers a frame of reference instead of an absolute date. When the date is far enough in the past and an absolute date becomes desired, customizing the date to the user's timezone is useful. And if your site grows large enough that caching becomes useful, finding a way to display customized deltas and timezone information in a cacheable static page becomes an ideal solution.&lt;/p&gt;

&lt;p&gt;JavaScript is an ideal solution for all three issues. With JavaScript you can place an absolute date in the web page and have the JS dynamically update it when the page is loaded. This can be used to calculate delta times and accommodate timezones as well. The result is that the page can embed the same date every time and thus becomes more cache-friendly.&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://typosphere.org"&gt;Typo&lt;/a&gt; blog engine (which runs this blog) comes with a useful MIT-licensed JavaScript in it's &lt;a href="http://trac.typosphere.org/browser/trunk/public/javascripts/typo.js"&gt;typo.js&lt;/a&gt; script. Just copy three of the JS date/time functions, wrap your dates with spans (using the appropriate class name and absolute date in the span title) and then call &lt;span class="fix"&gt;show_dates_as_local_time()&lt;/span&gt; when your page is finished loading. The two other functions you'll need are &lt;span class="fix"&gt;get_local_time_for_date(time)&lt;/span&gt; and &lt;span class="fix"&gt;distance_of_time_in_words(minutes)&lt;/span&gt;. This is what I did for &lt;a href="http://planet.catalystframework.org/"&gt;Planet Catalyst&lt;/a&gt;'s &lt;a href="http://plagger.org"&gt;Plagger&lt;/a&gt; theme a while back.&lt;/p&gt;

&lt;p&gt;Although it's pretty easy to accommodate timezones, the Typo script doesn't do that. I've done this for some projects and might post some code in the future but it's not hard.&lt;/p&gt;

&lt;p&gt;Customization and cacheability, two great advantages for using JavaScript to handle dates and times.&lt;/p&gt;</description>
      <pubDate>Mon, 05 Feb 2007 18:28:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:f3906b2c-8ae7-4b4c-a5b6-bc1bd25f1746</guid>
      <author>John Wang</author>
      <link>http://www.dev411.com/blog/2007/02/05/displaying-dates-and-times-using-javascript</link>
      <category>scalability</category>
      <category>typo</category>
      <category>javascript</category>
      <category>dhtml</category>
      <category>datetime</category>
    </item>
    <item>
      <title>"Displaying Dates and Times Using JavaScript" by jeyasamy@gmail.com</title>
      <description>&lt;p&gt;How to display real time dynamically using java script code&lt;/p&gt;


	&lt;p&gt;By
Jeyasree&lt;/p&gt;</description>
      <pubDate>Mon, 19 May 2008 23:00:42 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:74046b38-f636-4f58-b8e6-c3c4589a600d</guid>
      <link>http://www.dev411.com/blog/2007/02/05/displaying-dates-and-times-using-javascript#comment-246</link>
    </item>
    <item>
      <title>"Displaying Dates and Times Using JavaScript" by http://hype-free.blogspot.com/</title>
      <description>&lt;p&gt;Hello. I did something similar for Blogger (but it can be used generally):&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://hype-free.blogspot.com/2006/12/my-time.html" rel="nofollow"&gt;http://hype-free.blogspot.com/2006/12/my-time.html&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 03 Apr 2007 01:37:43 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:8388d280-3be6-4e93-a72e-c0952cb26fa5</guid>
      <link>http://www.dev411.com/blog/2007/02/05/displaying-dates-and-times-using-javascript#comment-167</link>
    </item>
  </channel>
</rss>
