/**
* java.time.Instant
* java.time.Duration
* Instant 默认使用UTC时区:2019-01-24T14:01:32.258Z
* mongo中的时间与系统时间相差了8个小时,这是因为mongo中的date类型以UTC(Coordinated Universal Time)存储,就等于GMT(格林尼治标准时)时间。而系统时间使用的是GMT+0800时间,两者正好相差8个小时。
* UTC + 时区差 = 本地时间 北京时区是东八区,领先UTC八个小时
* Duration:用于计算两个“时间”间隔
*/
public void timeInterval() throws InterruptedException{
Instant start = Instant.now();
Thread thread = new Thread();
thread.sleep(2000);
Instant end = Instant.now();
System.out.println("总耗时={}ms:"+Duration.between(start, end).toMillis());//总耗时={}ms:2007
System.out.println(start);//2019-08-07T03:22:17.737Z
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间 2019-08-07 11:22:17
}

/**
* java.time.LocalDate
* LocalDate的使用
* 计算两个日期之间间隔多少天
* 使用Period来获取间隔,用于计算两个“日期”间隔
*/
public void dateInterval(){
LocalDate startDate = LocalDate.of(2019, 1, 1);
LocalDate endDate = LocalDate.now();

Period period = Period.between(startDate, endDate);
System.out.println("日期间隔为:"+period); //日期间隔为:P7M6D
System.out.println("日期间隔为:"+period.getYears()+"年-"+period.getMonths()+"月-"+period.getDays()+"日"); //日期间隔为:0年-7月-6日

}

最新文章

  1. java根据标点英文分词
  2. springboot 使用c3p0数据库连接池的方法
  3. ASPxSpinEdit 控件的三元判断
  4. 关于Kb/s,KB/s的一些知识
  5. cut DEMO
  6. 两个实用的Python的装饰器
  7. Headfirst设计模式的C++实现——观察者模式(Observer)
  8. AS3中释放优化的几条常识
  9. mysql根据查询结果批量更新多条数据(插入或更新)
  10. 结对作业_core组
  11. python练习四—简单的聊天软件
  12. MySQL之实现Oracle中的rank()函数的功能
  13. Spring Security(十):3. What’s New in Spring Security 4.2 (新功能)
  14. jmeter(二十三)分布式测试
  15. telnet服务搭建
  16. Ring0 - 链表
  17. 使用 oracle pipelined 返回一个结果集;
  18. OS X 安装pyspider
  19. 洛谷P1186玛丽卡
  20. Java将数据库数据导入EXCEL

热门文章

  1. 关于iphone手机上点击事件不起作用
  2. kafka学习(二)-------- 什么是Kafka
  3. c语言进阶11-算法设计思想
  4. 使用 Spring Framework 时常犯的十大错误
  5. python函数闭包-装饰器-03
  6. 在vue中创建自定义指令
  7. Visual Studio 调试系列2 基本调试方法
  8. 自动生成Mybatis的Mapper文件
  9. python3 导入包总提示no moudle named xxx
  10. Android 虹软人脸识别SDK-人脸对比