ISO8601DateUtils.jsm

The ISO8601DateUtils.jsm JavaScript code module provides methods that make it easy to convert JavaScript Date objects into ISO 8601 format date strings and back.

To use this, you first need to import the code module into your JavaScript scope:

Components.utils.import("resource://gre/modules/ISO8601DateUtils.jsm");

Once you've imported the module, you can then use the ISO8601DateUtils object it exports.

Using the ISO 8601 date utilities

To convert a date string into a Date object, simply use:

dateObj = ISO8601DateUtils.parse(dateString);

To convert a Date object into a date string:

dateString = ISO8601DateUtils.create(dateObj);

Method overview

String create(aDate);
Date parse(aDateString);

Methods

create

Creates an ISO 8601 format date string, e.g. "2010-05-15T13:45:00Z", from a JavaScript Date object.

String create(
  aDate
);
Parameters
aDate
A JavaScript Date object to translate into an ISO 8601 format string.
Return value

An ISO 8601 format date string.

parse

Converts an ISO 8601 format date string into a JavaScript Date object.

Date parse(
  aDateString
); 
Parameters
aDateString
An ISO 8601 format date string.
Return value

A JavaScript Date object corresponding to the specified date string.

See also

Document Tags and Contributors

 Contributors to this page: teoli, Yansky0, fscholz, Torisugari, trevorh, MKaply, BenB, Sheppy
 Last updated by: teoli,