计算两个时间相差的秒数,直截了当,简单明了!
public static void main(String[] args) throws ParseException { String startTime = "2021-10-18 14:05:00"; String endTime = "2021-10-18 14:07:00"; System.out.println(getTime(startTime, endTime)); } //计算两个时间相差的秒数 public static long getTime(String startTime, String endTime) throws ParseException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long eTime = df.parse(endTime).getTime(); long sTime = df.parse(startTime).getTime(); long diff = (eTime - sTime) / 1000; return diff; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)