strftime() in JavaScript

Philip "Bluesmoon" Tellis has posted a tiny (under 3K minified) JavaScript library to format dates, inspired by PHP's strftime()

Examples:

d.strftime('%Y/%m/%d')
» en: 2008/04/25
» fr: 2008/04/25
» de: 2008/04/25

d.strftime('%A, %d %B')
» en: Friday, 25 April
» fr: Vendredi, 25 Avril
» de: Freitag, 25 April

There's also a demo to fiddle with.

I've previously had fun with kinda like the opposite: translating human-readable times into JS Date objects. Also here and here you have strtotime() look-alikes that take human-readable dates and turn them into Date objects.

This entry was posted on Friday, April 25th, 2008 and is filed under JavaScript, php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

5 Responses to “strftime() in JavaScript”

  1. Mojo Says:

    I like it. I’ve also been using the date parsing lib from Baron Schwartz
    http://code.google.com/p/flexible-js-formatting/

  2. Elida Germer Says:

    I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn a lots of new stuff here than anybody else!

  3. horacio Says:

    horacio…

    [...]strftime() in JavaScript / Stoyan’s phpied.com[...]…

  4. bulging Says:

    Ikusi dut duzun got post berri bat i oro har bultzatuko baino gehiago hemen, ez dute i esker esan til orain comment-etan argitaratua, i maite zure mezuak. Eskerrik asko!

  5. F-Hauri Says:

    I’m really impressed! Great work, nice, clean and efficient! Well written, bravo!!

    Question: Is there a way to link “navigator.language” by default?

    So I could write:

    out=new Date(inputValue).strftime(‘%a %d %b %Y %T’);

    instead of:

    out=new Date(inputValue);
    out.locale=navigator.language;
    out=cont.strftime(‘%a %d %b %Y %T’);

    Thanks for sharing this!!

Leave a Reply