I am grabbing a node from XML that returns the date like this :
2011-06-24T03:00:00
If I try to run new Date I am getting a NaN error.
var shippedDate = new Date($j(this).find("Shipment").find("Date").text())
$j("#result").append(shippedDate.getDate() + "/" + shippedDate.getMonth() + "/" + shippedDate.getFullYear() );
I am thinking I need to use a regular expression to grab everything before the T and drop the rest then it will work ?
Can someone please show me what that regex would look like or if there is another solution?
I think there might be an issue with how you are calling $j(this) because when I strip it all out, it works:
var shippedDate = new Date("2011-06-24T03:00:00");
$("#result").append(shippedDate.getDate() + "/" + shippedDate.getMonth() + "/" + shippedDate.getFullYear() );
http://jsfiddle.net/jasongennaro/Ry9u8/
It works just fine for me
var somedate = new Date('2011-06-24T03:00:00');
// Fri Jun 24 2011 03:00:00 GMT+0300 (GTB Daylight Time)
demo at http://jsfiddle.net/gaby/8Xwbj/2/
Are you sure the $j(this).find("Shipment").find("Date").text() returns what you expect it to ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With