Converting XML Timestamp to Javascript Date

From CDYNE Wiki
Jump to navigation Jump to search

This javascript function will convert a timestamp from XML to a JavaScript date.

CDYNE's use

This works great with our Phone Notify! service when you are trying to send a phone call at an exact time or if you to use the responses back from our xml Web Service.

Code Example

Example:

1 var StartT = "2006-08-29T01:18:15.001Z";
2 Status.innerText = TimeStampToDate(StartT);

Function:

 1 function TimeStampToDate(xmlDate)
 2 {
 3     var dt = new Date();
 4     var dtS = xmlDate.slice(xmlDate.indexOf('T')+1, xmlDate.indexOf('.'))
 5     var TimeArray = dtS.split(":");
 6     dt.setUTCHours(TimeArray[0],TimeArray[1],TimeArray[2]);
 7     dtS = xmlDate.slice(0, xmlDate.indexOf('T'))
 8     TimeArray = dtS.split("-");
 9     dt.setUTCFullYear(TimeArray[0],TimeArray[1],TimeArray[2]);
10     return dt;
11 }