Dojo Date Conversion ~ IS0-8601 to Epoch

Fiddle exploring how to parse a ISO-8601 formatted date string and convert the resulting date object to Epoch Time format.

by brady houseknecht

HTML

<div id="container">
    <table class="table" cellpadding="2" cellspacing="2" border="2" width="100%">
        <tr>
            <th>input string
                <br/>
            </th>
            <th>parsed date (toUTCString)
                <br/>
            </th>
            <th>epoch timestamp (getTime)</th>
        </tr>
        <tr>
            <td>2013-12-02</td>
            <td id="utcSlot"></td>
            <td id="epochSlot"></td>
        </tr>
    </table>
    <br />
    <br />
</div>

JavaScript

require([
    'dojo/dom',
    'dojo/dom-construct',
    'dojo/date/stamp'], function (dom, domConstruct, stamp) {
    var utcSlot = dom.byId('utcSlot'),
        epochSlot = dom.byId('epochSlot'),
        dateObject = stamp.fromISOString('2013-12-02'),
        epochString = dateObject.getTime(),
        utcString = dateObject.toUTCString(),
        epochHtml = '<i>' + epochString + '</i>',
        utcHtml = '<i>' + utcString + '</i>';
    console.log('utcDateString');
    console.log(utcString);
    console.log('epochString');
    console.log(epochString);
    domConstruct.place(utcHtml, utcSlot);
    domConstruct.place(epochHtml, epochSlot);
});