ISO 8601 extended format YYYY-MM-DDTHH: mm: ss. sssZ example: (section circled with a red border)
Note: This format is supported only when ECMAScript 5 is compatible. Browsers that support this time format include IE9, Chrome, FireFox, Safari, etc. IE browser before IE9 does not support this time format.
To convert an ISO 8601 time type to a UTC time type, follow these steps (compatible and not compatible with ECMAScript 5 browsers ):
[Javascript]
Date. prototype. setISO8601 = function (string ){
Var regexp = "([0-9] {4}) (-([0-9] {2}) (-([0-9] {2})" +
"(T ([0-9] {2}) :( [0-9] {2}) (:( [0-9] {2 })(\. ([0-9] + ))?)? "+
"(Z | ([-+]) ([0-9] {2}) :( [0-9] {2 })))?)?)?)? ";
If (string)
{
Var d = string. match (new RegExp (regexp ));
Var offset = 0;
Var date = new Date (d [1], 0, 1 );
If (d [3]) {
Date. setMonth (d [3]-1 );
}
If (d [5]) {
Date. setDate (d [5]);
}
If (d [7]) {
Date. setHours (d [7]);
}
If (d [8]) {
Date. setMinutes (d [8]);
}
If (d [10]) {
Date. setSeconds (d [10]);
}
If (d [12]) {
Date. setMilliseconds (Number ("0." + d [12]) * 1000 );
}
If (d [14]) {
Offset = (Number (d [16]) * 60) + Number (d [17]);
Offset * = (d [15] = '-')? 1:-1 );
}
Offset-= date. getTimezoneOffset ();
Time = (Number (date) + (offset x 60x1000 ));
This. setTime (Number (time ));
}
Else
{
Return;
}
}
The reference method is as follows:
[Html]
Var today = new Date ();
Today. setISO8601 (temprature_time_sorted_uniq [I]. tm );
Temprature_time_sorted_uniq [I]. tm is the time parameter of the ISO 8601 type passed to the function. The value is as follows:
The converted value is:
To convert the UTC format to ISO 8601
[Html]
Function ISODateString (d ){
Function pad (n ){
Return n <10? '0' + n: n
}
Return d. getUTCFullYear () + '-'
+ Pad (d. getUTCMonth () + 1) + '-'
+ Pad (d. getUTCDate () + 'T'
+ Pad (d. getUTCHours () + ':'
+ Pad (d. getUTCMinutes () + ':'
+ Pad (d. getUTCSeconds () + 'Z'
}
Reference Method: