时间日期操作组件joda 简单体验:
构造方法&取出3个月之前的日期时间
@Test
public void testJoda1() {
DateTime dateTime=new DateTime(2017, 5, 31, 18, 23,55);
String s1 = "-";
String s2 = "3";
int minus = Integer.parseInt(s1 + s2);
System.out.println(minus);
dateTime = dateTime.plusMonths(minus);
System.out.println(dateTime.toString("yyyyMMddHHmmss"));
}
取出当前日期的年月日,返回int
@Test
public void testJoda2() {
DateTime dateTime = new DateTime();
System.out.println("year:" + dateTime.getYear());
System.out.println("month:" + dateTime.getMonthOfYear());
System.out.println("day:" + dateTime.getDayOfMonth());
}
取出一天前的三个月前的日期时间,格式化输出(just like SimpleDateFormat)
@Test
public void testJoda3() {
System.out.println(new DateTime().plusDays(-1).toString("yyyyMMdd"));
}