java.time.LocalDateTime

两日期相差天数

LocalDateTimeStart.until(1L or -1L, ChronoUnit.DAYS)
注意:当参数为ChronoUnit.MONTHS时,计算结果会向下取整,比如:当实际月数为一个多月时,计算结果为1

日期比较

LocalDateTime1.compareTo(LocalDateTime2)  >=< 0

日期转换

org.joda.time.LocalDateTime—>java.util.Date

Date 转 LocalDateTime

new LocalDateTime(new Date())

LocalDateTime 转 Date

new LocalDateTime().toDate()

LocalDateTime 转 String

new LocalDateTime().toString("yyyy-MM-dd HH:mm")

String 转 LocalDateTime

DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");      
DateTime dateTime = DateTime.parse("2012-12-21 23:22:45", format);   

java.time.LocalDateTime—>java.util.Date

Date 转 LocalDateTime

LocalDateTime localDateTime = LocalDateTime.ofInstant(new Date().toInstant(),  ZoneId.systemDefault());

LocalDateTime 转 Date

LocalDateTime localDateTime = LocalDateTime.now();
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
java.util.Date date = Date.from(instant);

LocalDateTime 转 String

DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy/MM/dd");
String nowStr = df.format(LocalDateTime.now()));

String 转 LocalDateTime

DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime parse = LocalDateTime.parse("2017/01/01 08:01:01",df);

你可能感兴趣的:(java)