jQuery/JS - How to compare two date/time stamps?

前端 未结 5 871
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 18:53

I have two date/time stamps:

d1 = 2011-03-02T15:30:18-08:00 
d2 = 2011-03-02T15:36:05-08:00

I want to be above to compare the two:

5条回答
  •  心在旅途
    2020-12-10 19:29

    Your timestamps should be strings.

    var d1 = "2011-03-02T15:30:18-08:00";
    var d2 = "2011-03-02T15:36:05-08:00";
    
    if (new Date(d1) < new Date(d2)) {alert('newer')}
    

    Example: http://jsfiddle.net/hKPkF/

提交回复
热议问题