Daniel Rench

Web application development : Servers : Networks : E-Mail : DNS : Databases : Programming for hire

previous : contact : linkedin : code : links : pictures : facebook : twitter : next

Javascript strftime

<script type="text/javascript" src="http://dren.ch/js/strftime.js"></script>
<script type="text/javascript">
 var d = new Date();
 alert(d.strftime('Today is %A %B %e, day %j of the year %Y'));
</script>

Please refer to the FreeBSD strftime documentation if you are not familiar with the format codes.

"Known issues":

  • I made no attempts at i18n or l10n
  • Z and z worked under spidermonkey in a kludgy way and broke under IE and Safari, so they're commented out for now
  • Still missing %U, %V, and %W, and I also made no attempt to implement %E* and %O*
  • As a bonus of sorts, Number objects get a new pad() method (read the code if you're interested)
  • Overall it's only "lightly tested"
  • Somebody already did this
January 25, 2008 update: I never specified a license for http://dren.ch/js/strftime.js; it is public domain.

<< PongBounce (#2 in the Gratuitous Javascript Series) | Home | Portfolio | Contact | Antony & the Johnsons: Smells Pretty Good >>