我有一個自定義格式...爲什麼org.joda.time.DateTimeFormatter不能使用millis正確解析自定義日期時間?
// default our time zone to the machine local one.
private static final DateTimeZone LOCAL_TZ = DateTimeZone.getDefault();
// format of date (i.e., timestamp) is yyyy-MM-dd HH:mm:ss.S
private static final DateTimeFormatter YEAR_MONTH_DAY_HOUR_MINUTE_SECOND_MILLIS_FORMATTER =
new DateTimeFormatterBuilder()
.appendYear(4,4)
.appendLiteral('-')
.appendMonthOfYear(1)
.appendLiteral('-')
.appendDayOfMonth(1)
.appendLiteral(' ')
.appendHourOfDay(2)
.appendLiteral(':')
.appendMinuteOfDay(1)
.appendLiteral(':')
.appendSecondOfDay(1)
.appendLiteral('.')
.appendMillisOfDay(1)
.toFormatter().withZone(LOCAL_TZ);
我做這樣的事情......
String value = "2011-06-21 05:00:00.0";
YEAR_MONTH_DAY_HOUR_MINUTE_SECOND_MILLIS_FORMATTER.parseDateTime(value);
如果我在調試一下org.joda.time.DateTime,我會看到小時:分鐘:second.millis轉換爲00:00:00.0。
什麼給?我已經試過在HourOfDay,MinuteOfDay,SecondOfDay等等上使用minDigits。這是JodaTime 2.0中的錯誤嗎?或者(更可能)我自己的無知?
另請注意,除了將appendMillisOfDay更改爲appendMillisOfSecond以上之外,我還必須將appendMinuteOfDay更改爲appendMinuteOfHour,以使格式化程序按需要工作。錢幣!我覺得我好笨。 –