這個代碼怎么寫呀 求大佬簡單點 感謝感謝
uj5u.com熱心網友回復:
public static void main(String[] args) {System.out.println("DateUtils.main:"+new Date().getTime());
String yourTimeString = "1486448690841";
Long yourTime = Long.parseLong(yourTimeString);
Long theTime = new Date().getTime();
theTime.compareTo(yourTime);
System.out.println("比較大小"+theTime.compareTo(yourTime));
}
根據compareTo()方法的回傳值判斷 1是大于 0是等于 -1是小于
你寫幾個main方法運行一下,就知道了
uj5u.com熱心網友回復:
Date里有getTime()方法可以將時間轉換為毫秒數uj5u.com熱心網友回復:
public static void main(String[] args) {Long time = 1486448690841L;
//方式一
//新建一個date類
Date date = new Date();
//默認為當前時間
System.out.println("當前時間為:" + date);
//設定為你的毫秒數
date.setTime(time);
System.out.println("我設定的時間為:" + date);
// before 判斷兩個時間
System.out.println(date.before(new Date()));
//方式二
//獲取當前時間的毫秒數
long l = System.currentTimeMillis();
//直接比較兩個毫秒數 越早的時間越小
System.out.println(time < l);
}
uj5u.com熱心網友回復:
轉換成LocalDateTime,里邊有isAfter,isBefore等方法。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/169799.html
標籤:Java相關
上一篇:阿里監控和調優性能工具tprofiler 報錯,不能監控springboot2.0,但是springboot1.5.3可以
