Date Format 1.1

I've just updated my ColdFusion-inspired JavaScript Date Format script to version 1.0 1.1, and updated the documentation in the old post along with it. The new release includes "Z" (US timezone abbreviation) and "o" (UTC offset) flags as well as brevity enhancements from Scott Trenda, along with several other new features including a standalone dateFormat function, named and default masks (plus you can easily add your own), easier internationalization, etc.

This update includes one change which is not backwards compatible: mask characters and sequences no longer have to comprise entire words for them to be treated specially. The former handling was intended to make it dead-easy to mix literal characters into date masks, but ended up mostly just being a slight nuisance since most people didn't use it to embed dates in larger strings.

Check out the new Date Format!


Edit: Date Format is now integrated into two JavaScript frameworks:

  • CFJS is a library of almost 70 ColdFusion functions written in JavaScript by Chris Jordan. CFJS has used Date Format, which was a natural fit since it's largely based on ColdFusion's dateFormat and timeFormat functions, since version 0.1.
  • Chiron is an innovative, emerging JavaScript library by Kris Kowal. It's based on Python idioms, and at its heart is an advanced module loader and isolation system the likes of which hasn't been seen yet in the JavaScript world. In addition to integrating Date Format as a module called date.js, Chiron has also integrated my XRegExp library, and uses regular expressions from parseUri in its core. Expect to hear more about Chiron as it gets closer to 0.1 release.

4 thoughts on “Date Format 1.1”

  1. Not exactly. ISO 8601 (which covers the representation of dates and times, not formatting masks) uses a literal “Z” at the end of a time string to indicate that the time uses UTC/GMT/Zulu time. I.e., it’s the same as adding “+0000”. Using Date Format, you can add a literal Z to the end of a formatted string by wrapping it in quotes (see details in the Date Format documentation). According to ISO 8601, if you don’t include a literal Z, the timezone is assumed to be the local time unless you alternatively specify the UTC offset (which you can easily do using Date Format’s “o” flag or the named mask “isoFullDateTime”). The JavaScript Date and Date.prototype objects include a number of methods for working with date objects using UTC rather than local time.

    The use of “Z” as a flag to indicate that the timezone abbreviation should be embedded in the formatted string comes from the C and POSIX standards for formatting time (see the date utility and strftime function).

  2. It still isn’t a “US timezone abbreviation”, as stated it indicates a +0000 time offset, this is an offset from UTC and will always be several hours out from any US timezone. Zulu time was originally a military designation AFAIK.

  3. @Jules, of course a literal “Z” in an ISO 8601-formatted time does not indicate a US timezone. It indicates that UTC time is being used. It would not be right to append a literal “Z” unless the dateFormat function knew it was working with a UTC-based date object.

    Edit: Date Format 1.2 supports conversion to UTC time.

Leave a Reply

Your email address will not be published. Required fields are marked *