1

How can I compare these two date and time values:

date 1 = 2012年03月07日 11:55:18

date 2 = 2012年01月02日 11:02:44

and find the time difference between them?

asked Mar 7, 2012 at 12:24
1
  • Where do you get those values from? Commented Mar 7, 2012 at 12:38

3 Answers 3

2

you can get seconds difference with below code,you can convert that accordingly

var date1=new Date("2012-03-07 11:55:18");
var date2=new Date("2012-01-02 11:02:44");
var mSeconds=date1.getTime()-date2.getTime();
alert(mSeconds/1000);​

jsfiddle example

answered Mar 7, 2012 at 12:35
Sign up to request clarification or add additional context in comments.

Comments

0

you can convert the date objects to timestamps like date1.getTime() and then use those timestamps to get difference in milliseconds

answered Mar 7, 2012 at 12:26

Comments

0

You can create the two dates with the Javascript Date object and then compare them with the usual operators.

See W3 Schools Example

answered Mar 7, 2012 at 12:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.