码迷,mamicode.com
首页 > 其他好文 > 详细

JDK 8 三种时间获取方法 日期加减

时间:2019-05-29 20:48:08      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:sda   details   with   去除   方法   local   oca   获取   时间   

//2018-12-04
LocalDate localDate = LocalDate.now();

//16:14:56.892
LocalTime localTime = LocalTime.now();

//2018-12-04T16:14:56.892
LocalDateTime localDateTime = LocalDateTime.now();

//16:14:5(去除毫秒)
LocalTime time = LocalTime.now().withNano(0);

//2018-12-04 16:17:55
String now1 = LocalDateTime.now().withNano(0).toString().replace("T", " ");
String now2 = LocalDate.now()+" "+LocalTime.now().withNano(0);

 


//三天后
LocalDate afterThreeDays = LocalDate.now().plusDays(3);

//三天前
LocalDate threeDaysAgo = LocalDate.now().minusDays(3);

LocalDate now = LocalDate.now();
LocalDate date = LocalDate.parse("2020-01-30");
long day1 = now.toEpochDay();
long day2 = date.toEpochDay();
//相差多少天
long day = day2-day1;

原文:https://blog.csdn.net/Anenan/article/details/84790591

JDK 8 三种时间获取方法 日期加减

标签:sda   details   with   去除   方法   local   oca   获取   时间   

原文地址:https://www.cnblogs.com/shundong106/p/10946041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!