unix時間戳是從1970年1月1日(UTC/GMT的午夜)開始所經過的秒數,不考慮閏秒。
1,獲取當前時間的timestamp
Date date = new Date(); long stamp = date.getTime()/1000; System.out.println(stamp);
long timestamp = System.currentTimeMillis()/1000; System.out.println(timestamp);
2,獲取指定時間的timestamp
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-03-25 15:01:17"); long timestamp = date.getTime()/1000; System.out.println(timestamp);