java比较两个时间差,验证码有效期60秒

  • Post author:
  • Post category:java


private boolean overtimeCode(String firstTime,String lastTime,long overtime){
    boolean flag=false;
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date one;
    Date two;
    try {
        one = df.parse(firstTime);
        two = df.parse(lastTime);
        long time1 = one.getTime();
        long time2 = two.getTime();
        long diff = time2 - time1;
        if(diff/1000>overtime){
            flag=true;
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return flag;
}



版权声明:本文为u012726702原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。