Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How split this into new Date

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?

like image 637
Zac Avatar asked May 29 '26 13:05

Zac


2 Answers

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/

like image 140
Jason Gennaro Avatar answered Jun 01 '26 02:06

Jason Gennaro


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 ?

like image 23
Gabriele Petrioli Avatar answered Jun 01 '26 03:06

Gabriele Petrioli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!