Hello, I have a Google Map which is being supplied with data from an XML file. I am having problems defining one of the elements to simpleDateFormat. In firebug and in the output in my infoboxes it says undefined. The output is defined and formats it properly. I am just having problem defining the parsed XML element to simpleDateFormat.
The parsed input is from this XML which the element of question is <cap:expires>
<cap:expires>2013-05-02T19:00:00-05:00</cap:expires>
From this XML file
I have parsed it like this which gives me the new name expires.
var expires = nodeValue(entries[j].getElementsByTagName("cap:expires")[0]);
if (!expires) expires = nodeValue(entries[j].getElementsByTagName("expires")[0]);
Here is the simpleDateformat where I am trying to define expires.
function dateFromString(expires) {
var bits = expires.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(expires);
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;
If you need to see the entire code you can from this link
To see the result of the code with the map visit the link below. Mouse over a county and you see it says undefined.
http://www.mesquiteweather.net/googlemap.html
What am I doing wrong? I by no means know javascript at all. I have only started using it this past week only because I needed the use of Google Maps which uses Js.
Any help would be greatly appreciated!
-Thanks