ISO8601DateUtils.jsm

  • Revision slug: JavaScript_code_modules/ISO8601DateUtils.jsm
  • Revision title: ISO8601DateUtils.jsm
  • Revision id: 4022
  • Created:
  • Creator: BenB
  • Is current revision? No
  • Comment overstepped my own change due to network/response problems; 15 words removed

Revision Content

{{ gecko_minversion_header("1.9") }}

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 = ISO8601Utils.parse(dateString);

To convert a Date object into a date string:

dateString = ISO8601Utils.create(dateObj);

Method overview

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

Methods

create

Creates an ISO 8601 format date string, e.g. "2010-05-12T13: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

Revision Source

<p>{{ gecko_minversion_header("1.9") }}</p>
<p>The <span style="font-family: monospace;">ISO8601DateUtils</span><code>.jsm</code> JavaScript code module provides methods that make it easy to convert JavaScript <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a> objects into ISO 8601 format date strings and back.</p>
<p>To use this, you first need to import the code module into your JavaScript scope:</p>
<pre class="eval"><span class="nowiki">Components.utils.import("</span><a class=" external" href="resource://gre/modules/XPCOMUtils.jsm" rel="external nofollow" target="_blank" title="resource://gre/modules/XPCOMUtils.jsm"><span class="nowiki">resource://gre/modules/ISO8601DateUtils.jsm</span></a><span class="nowiki">");</span>
</pre>
<p>Once you've imported the module, you can then use the <code>ISO8601DateUtils</code> object it exports.</p>
<h2>Using the ISO 8601 date utilities</h2>
<p>To convert a date string into a <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a> object, simply use:</p>
<pre>dateObj = ISO8601Utils.parse(dateString);
</pre>
<p>To convert a <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a> object into a date string:</p>
<pre>dateString = ISO8601Utils.create(dateObj);
</pre>
<h2>Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><code>String create(aDate);</code></td> </tr> <tr> <td><code>Date parse(aDateString);</code></td> </tr> </tbody>
</table>
<h2>Methods</h2>
<h3>create</h3>
<p>Creates an ISO 8601 format date string, e.g. "2010-05-12T13:45:00Z", from a JavaScript <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a> object.</p>
<pre>String create(
  aDate
);
</pre>
<h6>Parameters</h6>
<dl> <dt><code>aDate</code></dt> <dd>A JavaScript <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a> object to translate into an ISO 8601 format string.</dd>
</dl>
<h6>Return value</h6>
<p>An ISO 8601 format date string.</p><h3>parse</h3>
<p>Converts an ISO 8601 format date string into a JavaScript <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a> object.</p>
<pre>Date parse(
  aDateString
); 
</pre>
<h6>Parameters</h6>
<dl> <dt>aDateString</dt> <dd>An ISO 8601 format date string.</dd>
</dl>
<h6>Return value</h6>
<p>A JavaScript <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a> object corresponding to the specified date string.</p>
<h2>See also</h2>
<ul> <li><a class="internal" href="/en/JavaScript_code_modules/Using_JavaScript_code_modules" title="en/JavaScript code modules/Using JavaScript code
    modules">Using JavaScript code modules</a></li> <li><a class="internal" href="/en/JavaScript_code_modules" title="en/JavaScript code
    modules">JavaScript code modules</a></li> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core JavaScript 1.5 Reference/Global Objects/Date"><code>Date</code></a></li>
</ul>
Revert to this revision