1.添加maven依赖
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.4</version>
</dependency>
2.以下列举了本人平时常用的一些操作(还有很多功能不一一列举)
public static void main(String[] args) {
String time = "2019-11-11 00:00:00";
String format = "yyyy-MM-dd HH:mm:ss";
//获取当前天
DateTime now = DateTime.now();
//获取时间戳
Long timesTemp = now.getMillis();
//将时间格式字符串转为改时间对象
DateTime activityTime = DateTime.parse(time, DateTimeFormat.forPattern(format));
//将时间对象转为某种字符串格式
String formatTime = activityTime.toString(format);
//往后推天、小时、分钟等
DateTime plusDay = now.plusDays(1);
DateTime plusHours = now.plusHours(2);
//往前推天、小时、分钟等
DateTime minusDay = now.minusDays(1);
DateTime minusHours = now.minusHours(2);
//获取当前天的"0"点
DateTime nowZeroTime = now.withTimeAtStartOfDay();
//时间戳转 DateTime对象
DateTime newDateTime = new DateTime(1547785369669L);
//DateTime 转为 java.util.Date
Date date = newDateTime.toDate();
}
3.java8对时间的处理
https://blog.csdn.net/wsywb111/article/details/79815481