ISO 8601 Date String with Node.JS for AmazonWS
When I tried in javascript to calculate the ISO 8601 Date String, I noticed that there is already such method on the Date object.
This method is called toISOString and is not yet documented at the mdc page.
This date format is needed for instance for the amazon web services.
If you need a implementation anyways (even though toISOString should be available), here is a plain javascript implementation:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var pad_two = function(n) {
return (n < 10 ? '0' : '') + n;
};
var pad_three = function(n) {
return (n < 100 ? '0' : '') + (n < 10 ? '0' : '') + n;
};
return [
date.getUTCFullYear(),
'-',
pad_two(date.getUTCMonth() + 1),
'-',
pad_two(date.getUTCDate()),
'T',
pad_two(date.getUTCHours()),
':',
pad_two(date.getUTCMinutes()),
':',
pad_two(date.getUTCSeconds()),
'.',
pad_three(date.getUTCMilliseconds()),
'Z',
].join('');
}
It takes a javascript date object and converts it to an iso 8601 date string.
Messages
its fun
Are you using a beta of node.js? Mine doesn't have date.getUTCFullYear() and other methods.
effe
add ae


