简体   繁体   中英

Convert plain string date into required format and difference between two dates

I am getting date from XML but date is in plain string format. I would like to create the difference from today's date and time and the date and time which i am getting from xml.

For example i am getting date as a plain string in this format (2012-10-17T08:15:19.500-05:00).Now when i am doing difference with current date&time than i need to display something like this "2:hr,32min".

Any help/suggestion would be a great input.

Thanks

This should work:

var myDate = new Date( '2012-10-17T08:15:19.500-05:00' ),
    newDate = new Date();

Browser results can vary when parsing dates. I have a test Fiddle here .

To get the difference between dates: var diff = myDate - newDate; and to convert that back to something useful: Convert time interval given in seconds into more human readable form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM