从品牌网站建设到网络营销策划,从策略到执行的一站式服务
一、获取当前时区时间:
Instant.now().atZone(ZoneId.systemDefault())
二、创建Instant实例
Instant now = Instant.now();
System.out.println(“now:”+now);
控制台输出:
now:2018-07-09T08:59:08.853Z
注意:通过这种方式获取的时间戳与北京时间相差8个时区,需要修正为北京时间,通过查看源代码发现Instant.now()使用等是UTC时间Clock.systemUTC().instant()。LocalDate、LocalDateTime 的now()方法使用的是系统默认时区 不存在Instant.now()的时间问题。
###解决方法
增加8个小时
Instant now = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(8));
System.out.println(“now:”+now);
控制台输出:
now:2018-07-09T16:58:48.188Z
三、Instant获取long类型的10位秒数、13位毫秒数
Instant now = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(8)); System.out.println(“秒数:”+now.getEpochSecond()); System.out.println(“毫秒数:”+now.toEpochMilli());
成都网站建设公司地址:成都市青羊区太升南路288号锦天国际A座10层 建设咨询028-86922220
成都快上网科技有限公司-四川网站建设设计公司 | 蜀ICP备19037934号 Copyright 2020,ALL Rights Reserved cdkjz.cn | 成都网站建设 | © Copyright 2020版权所有.
专家团队为您提供成都网站建设,成都网站设计,成都品牌网站设计,成都营销型网站制作等服务,成都建网站就找快上网! | 成都网站建设哪家好? | 网站建设地图