DateTime start = new DateTime().withYear(1884);
System.out.println(start);
System.out.println(start.minusYears(1));
输出
1884-01-11T08:26:10.234-08:00
1883-01-11T08:26:10.234-07:52:58
编辑1:我不正确。它没有删除 1.02 秒
DateTime start = new DateTime().withYear(1884);
DateTime other = start.minusYears(1);
long diffMs = start.getMillis() - other.getMillis(); //31536422000
编辑2:
toString();
有趣的是,我对- ( -08:00
, -07:52:58
)的输出感到困惑
编辑3:
使用 Java 日历,我看不出有任何区别:
Calendar cal = Calendar.getInstance();
cal.set(start.getYear(),
start.getMonthOfYear(),
start.getDayOfMonth(),
start.getHourOfDay(),
start.getMinuteOfHour(),
start.getSecondOfDay());
System.out.println(cal.getTime());
cal = Calendar.getInstance();
cal.set(start.getYear()- 1,
start.getMonthOfYear(),
start.getDayOfMonth(),
start.getHourOfDay(),
start.getMinuteOfHour(),
start.getSecondOfDay());
System.out.println(cal.getTime());
输出:
Mon Feb 11 18:46:42 PST 1884
Sun Feb 11 18:46:42 PST 1883