Results 1 to 2 of 2

Thread: Converting XML date from XML feed

  1. #1
    Join Date
    May 2013

    Converting XML date from XML feed

    I hope I explain this right and the best I can. Let me first start by saying I know nothing about Javascript at all so please be patient with me. HTML/CSS/PHP is normally all I deal with. Only reason I am working with it now is because I am dealing with Google Maps V3. I have been searching the web to get this far for a week and now I am stuck and can't find exactly how to do this. I know it is something simple for those fluent in javascript.

    I have a test Google Map from this link which you can also view the code.


    Now if you mouse over a polygon you will see an infobox pops up with the title and date. The date is outputted properly when you view it from the infoboxes. It shows the same date for all the infoboxes because I don't know how to take the variable I parsed from the XML file to be converted. Mainly because I have hard coded and ISO 8601 format to test the output in this line....

    var dt = (dateFromString('2013-05-02T11:08:00-6:00'));
    Now I have it setup and outputting properly the way I need it. Now this is where I am stuck. How do I take the parsed element from the XML file to be converted with the following snippet that is in my code for doing the conversion using SimpleDateFormat that I currently have it to output the correct date format?

    function dateFromString(s) {
      var bits = s.split(/[-T:+]/g);
      var d = new Date(bits[0], bits[1]-1, bits[2]);
      d.setHours(bits[3], bits[4], bits[5]);
      // Get supplied time zone offset in minutes
      var offsetMinutes = bits[6] * 60 + Number(bits[7]);
      var sign = /\d\d-\d\d:\d\d$/.test(s)? '-' : '+';
      // Apply the sign
      offsetMinutes = 0 + (sign == '-'? -1 * offsetMinutes : offsetMinutes);
      // Apply offset and local timezone
      d.setMinutes(d.getMinutes() - offsetMinutes - d.getTimezoneOffset())
      // d is now a local time equivalent to the supplied time
    return (d);
    var days = ["Sun","Mon","Tues","Wed","Thur","Fri","Sat"];
    var months =['Jan','Feb','March','April','May','June','July','Aug','Sept','Oct','Nov','Dec'];
    var ampm = " am";
    var dt = (dateFromString('2013-05-02T11:08:00-6:00'));
    var yr = dt.getFullYear();
    var mth = dt.getMonth();  // months in Javascript are 0-11 so May is month 4
    mth = months[mth];
    var dte = dt.getDate();
    var dy = dt.getDay();  // days are 0-6
    dy = days[dy];
    var hrs = dt.getHours();
    var h1 = hrs;
    var mins = dt.getMinutes();
    if (hrs >= 12) {ampm = " pm"}
    if (hrs >= 13) {hrs = hrs - 12}
    if (h1 == 0) {hrs = 12}
    if (hrs <10) {hrs = "0" + hrs};  // if  leading zero desired
    if (mins <10) {mins = "0" + mins};
    var dtstring = dy + ", " + mth + " " + dte + ", " + yr + " at " + hrs + ":" + mins + ampm;

    Here is to the link to the XML file


    I have parsed <cap:expires> to create the variable of expires if you view the source of the code from the first link. I just don't know how to take that parsed variable and input it with the SimpleDateFormat so the infboxes are showing the converted date format for each entry from the XML file

    Please be easy and patient with me. I catch on quick but I do not really know anything about Javascript or how it works and the terms. I have gotten this far after endless searches on the internet. So if anyone can offer me some advice I would be greatly appreciative. I am sure it is something really easy but I haven't been able to find anything about converting ISO 8601 with javascript from XML. It is possible I probably didn't know the correct search terms or what I am looking for or how to word it. I hope I have provided enough information. If I need to provide any more please just ask.


  2. #2
    Join Date
    May 2013
    If I need to add more info please let me know.

    I have it defined now but it still isn't working and firebug is telling me expires isn't defined.

    You can see the current code I am working with from the link in the original post.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center