Java程序获取日期之间的毫秒数
假设以下是我们想要毫秒差的两个日期-
LocalDateTime dateOne = LocalDateTime.now(); LocalDateTime dateTwo = LocalDateTime.of(2019, 4, 10, 11, 20);
现在,使用MILLIS.between获得上述两个日期之间的毫秒数-
long res = MILLIS.between(dateOne, dateTwo);
示例
import java.time.LocalDateTime;
import static java.time.temporal.ChronoUnit.MILLIS;
public class Demo {
public static void main(String[] argv) {
LocalDateTime dateOne = LocalDateTime.now();
LocalDateTime dateTwo = LocalDateTime.of(2019, 4, 10, 11, 20);
System.out.printf("Date One = "+dateOne);
System.out.printf("\nDate Two = "+dateTwo);
long res = MILLIS.between(dateOne, dateTwo);
System.out.println("\nMilliseconds between two dates = " + res);
}
}输出结果
Date One = 2019-04-12T11:18:29.654947300 Date Two = 2019-04-10T11:20 Milliseconds between two dates = -172709654
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短