SEARCH :
This SectionSite Wide
 

Ektron's Developer Group Blog

A blog for Ektron users, by Ektron Developers

Parse XML date in JavaScript

 Permanent link

A JavaScript function to parse an XML (ISO-8601) date string (e.g., "2008-01-18") that returns a JavaScript Date object.

function parseDate(xmlDate)
{
      if (!/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}/.test(xmlDate)) {
           throw new RangeError("xmlDate must be in ISO-8601 format YYYY-MM-DD.");
      }
      return new Date(xmlDate.substring(0,4), xmlDate.substring(5,7)-1, xmlDate.substring(8,10));
}

The code snippet below then converts the Date object to localized string.

      strXmlDate = "2008-01-18";
       oTempDate = parseDate(strXmlDate);
       if (oTempDate.toLocaleDateString)
       {
          strDate = oTempDate.toLocaleDateString();
       }
       else
       {
          strDate = oTempDate.toLocaleString();
       }


Unsure as to what this program is going to do, but just getting started with my trial membership.

Regards
Jay
Posted by: jayhiatt( Visit ) at 4/1/2008 12:51 AM


so nice
Posted by: hi( Visit ) at 9/9/2008 2:56 PM


This is a comment with lines
Line 1
Line 2
Line 3
Posted by: Robert Porter at 10/24/2008 5:04 PM


This is a comment with lines
Line 1
Line 2
Line 3
Posted by: Robert Porter at 10/24/2008 5:04 PM