0

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

ravi
  • 71
  • 1
  • 3
  • 11

1 Answers1

1

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

Community
  • 1
  • 1
Kevin Boucher
  • 16,426
  • 3
  • 48
  • 55