How do I output an ISO-8601 formatted string in Javascript?
- by James A. Rosen
I have a date object from which I'd like to render an HTML snippet like <abbr title="2010-04-02T14:12:07">A couple days ago</abbr>. I have the "relative time in words" portion from another library. How do I render the title portion?
I've tried the following:
isoDate: function(msSinceEpoch) {
var d = new Date(msSinceEpoch);
return d.getUTCFullYear() + '-' + (d.getUTCMonth() + 1) + '-' + d.getUTCDate() + 'T'
d.getUTCHours() + ':' + d.getUTCMinutes() + ':' + d.getUTCSeconds();
}
But that gives me
"2010-4-2T"