javascript - Convert datestamp from XML file -
i have google map application displays data xml file. when mouse on returns info including data. date xml file this...
<cap:expires>2013-05-02t00:00:00-05:00</cap:expires>
i have bit of code converts it....
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]); // 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 sign offsetminutes = 0 + (sign == '-'? -1 * offsetminutes : offsetminutes); // apply offset , local timezone d.setminutes(d.getminutes() - offsetminutes - d.gettimezoneoffset()) // d local time equivalent supplied time return (d); } var days = ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]; var months =['january','february','march','april','may','june','july','august','september','october','november','december']; var ampm = " am"; var dt = (datefromstring("yyyy-mm-dd't'hh:mm:ssz")); var yr = dt.getfullyear(); var mth = dt.getmonth(); // months in javascript 0-11 may month 4 mth = months[mth]; var dte = dt.getdate(); var dy = dt.getday(); // days 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 0 desired if (mins <10) {mins = "0" + mins}; var dtstring = dy + " " + mth + " " + dte + " " + yr + " " + hrs + ":" + mins + ampm;
which works great when hard code converts it.
var dt = (datefromstring( '2013-05-02t11:08:00-6:00'));
my problem how , insert element xml knows convert? have set output, not sure put in input convert. have included links both map , xml file in case needs see full code see how it's set up.
there special class in java deal xml datetime javax.xml.datatype.xmlgregoriancalendar
xmlgregoriancalendar xgc = datatypefactory.newinstance().newxmlgregoriancalendar("2013-05-02t00:00:00-05:00");
now use methods necessary fields. can convert gregoriancalendar , date
Comments
Post a Comment