約達時間分鐘,我有這個簡單的代碼:的持續時間或間隔
DateTime date = new DateTime(dateValue);
DateTime currentDate = new DateTime(System.currentTimeMillis());
System.out.println("date: " + date.toString());
System.out.println("currentDate: " + currentDate.toString());
Period period = new Period(currentDate, date);
System.out.println("PERIOD MINUTES: " + period.getMinutes());
System.out.println("PERIOD DAYS: " + period.getDays());
Duration duration = new Duration(currentDate, date);
System.out.println("DURATION MINUTES: " + duration.getStandardMinutes());
System.out.println("DURATION DAYS: " + duration.getStandardDays());
我想簡單地找出天的兩個隨機日期之間的數量和分鐘。
這是這段代碼的輸出:
date: 2012-02-09T00:00:00.000+02:00
currentDate: 2012-02-09T18:15:40.739+02:00
PERIOD MINUTES: -15
PERIOD DAYS: 0
DURATION MINUTES: -1095
DURATION DAYS: 0
我猜,我做錯了什麼,我看不出有什麼。
哦,我從來沒有完全明白這一點。我開悟了。 – 2012-02-09 22:46:27
@LouisWasserman:我在將Joda Time移植到.NET時有點特殊,所以我可能比大多數人對它有更好的理解:) – 2012-02-09 22:49:24