我刚开始使用Joda-Time,并让它以24 小时制(“军事时间”)正确显示我的日期,但我宁愿它是上午/下午。查了一下,它提到了hourOfDay,我认为这是 HH 值,所以我尝试编写一个循环,将其分解为 AM/Pm,但它从未成功。
DateTime dtf = new DateTime(wikiParsedDate);
if (hourOfDay == 00) {
hourOfDay == 12;
DateTimeFormatter builder = DateTimeFormat.forPattern( "dd-MM-yyyy HH:mm:ss.SS'AM" );
return builder.print(dtf);
} else if (0 < hourOfDay && hourOfDay < 12) {
DateTimeFormatter builder = DateTimeFormat.forPattern( "dd-MM-yyyy HH:mm:ss.SS'AM" );
return builder.print(dtf);
} else if (hourOfDay > 12) {
hourOfDay - 12 == hourOfDay;
DateTimeFormatter builder = DateTimeFormat.forPattern( "dd-MM-yyyy HH:mm:ss.SS'PM" );
return builder.print(dtf);
}
}