[Israel.pm] JavaScript's Grip of the Day: Formatting Dates

Shlomi Fish shlomif at iglu.org.il
Tue Nov 25 12:50:39 PST 2008

As I was working on a new Greasemonkey script today, I needed a way to parse 
the date from a string, and format it into DD-MM-YYYY. Parsing the date 
turned out to be easy:


However, now I wanted to find a way to format it. I landed on this post:


As it turns out, JavaScript has no built-in method equivalent to strftime(), 
and this post supplies an alternative. So I thought to myself: no problem - 
I'll just use sprintf. But, lo and behold - no sprintf for us:


So I bit the bullet and copy-and-pasted the date-time-format code into my 
script. The format supported by it is not strftime()-compatible, but rather 
something like ColdFusion. And the script now works.

But I'm really surprised that JavaScript doesn't even have something like 
sprintf. That's really lame.


	Shlomi Fish

Shlomi Fish       http://www.shlomifish.org/
"Humanity" - Parody of Modern Life - http://xrl.us/bkeut

Shlomi, so what are you working on? Working on a new wiki about unit testing 
fortunes in freecell? -- Ran Eilam

More information about the Perl mailing list