Date comparison - How to check if 20 minutes have passed?

后端 未结 6 1775
遇见更好的自我
遇见更好的自我 2021-02-05 00:44

How to check if 20 minutes have passed from current date?

For example:

var start = DateTime.Now;
var oldDate = \"08/10/2011 23:50:31\"; 

    if(start ?         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 01:19

    I was able to accomplish this by using a JodaTime Library in my project. I came out with this code.

    String datetime1 = "2012/08/24 05:22:34";
    String datetime2 = "2012/08/24 05:23:28";
    
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss");
    DateTime time1 = format.parseDateTime(datetime1);
    DateTime time2 = format.parseDateTime(datetime2);
    Minutes Interval = Minutes.minutesBetween(time1, time2);
    Minutes minInterval = Minutes.minutes(20);
    
    if(Interval.isGreaterThan(minInterval)){
      return true;
    }
    else{
      return false;
    }
    

    This will check if the Time Interval between datetime1 and datetime2 is GreaterThan 20 Minutes. Change the property to Seconds. It will be easier for you know. This will return false.

提交回复
热议问题