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
andkjaer
4,09510 gold badges39 silver badges46 bronze badges
-
Where do you get those values from?user447356– user4473562012年03月07日 12:38:26 +00:00Commented Mar 7, 2012 at 12:38
3 Answers 3
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);
answered Mar 7, 2012 at 12:35
Balaswamy Vaddeman
8,6003 gold badges33 silver badges40 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
Saket Patel
6,7031 gold badge29 silver badges36 bronze badges
Comments
You can create the two dates with the Javascript Date object and then compare them with the usual operators.
answered Mar 7, 2012 at 12:27
H.Rabiee
4,8673 gold badges29 silver badges36 bronze badges
Comments
lang-js