LocalDateTime time = LocalDateTime.of(2014, 11, 9, 0, 0);
int plusDays = 1000;
LocalDateTime time1 = time.plusDays(plusDays);
System.out.println("1000天后的时间为:" + time1);
同时支持几秒后,几小时后等等(如下图)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cda1770b91a1acb9886049e59aa65117.png)
Java的Date,Calendar类型使用起来并不是很方便,而且Date类(据说)有着线程不安全等诸多弊端。同时若不进行封装,会在每次使用时特别麻烦。于是Java8推出了线程安全、简易、高可靠的时间包。并且数据库中也支持LocalDateTime类型,在数据存储时候使时间变得简单。Java8这次新推出的包括三个相关的时间类型:LocalDateTime年月日十分秒;LocalDate日期;LocalTime时间;三个包的方法都差不多。
使用Date的弊端
使用Date输出的日期可读性差(在不进行日期格
当前时间:2019年10月24日。距离 JDK 14 发布时间(2020年3月17日)还有多少天?
// 距离JDK 14 发布还有多少天?
LocalDate jdk14 = LocalDate.of(2020, 3, 17);
LocalDate nowDate = LocalDate.now();
System.out.println("距离JDK 14 发布还有:"+nowDate.unt...
当你在做有关时间日期的操作时,你会想到用Date;
当你在做日期、月份、天数相加减时,你会想到用Calendar;
当你需要对时间日期进行格式化时,你会想到使用SimpleDateFormat或DateFormat下的其他子类;
但是,你必须知道,以上有关的时间日期操作对象,都是可变的、线程不安全的,同时,如果作为一个经常写过类
Calendar calendar1 = Calendar.getInstance();
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
calendar1.add(Calendar.DATE, -3);
String three_days_ago...
private LocalDateTime getExpirationTime(Integer number){
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
calendar.add(Calendar.DATE, number);
String three_days_after = sdf.format(calendar.
Calendar:它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法。
Calendar calendar2 = Calendar.getInstance();
SimpleDateFormat sdf2 = new SimpleDateFormat("yyy...
单不饱和脂肪酸:
Java中的LocalDateTime类的一个例字
从零开始的数据猿: