我有两个DateTime对象。第一次我刚走到午夜,第二次我想在12小时后(今天中午)开始。
两个物体都被设置为午夜刚刚消失。为什么会这样呢?我已经把12小时后定为长的,例如43300000。
提前感谢
DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y H:mm");
DateTime lastNightMidnight = new DateTime().toDateMidnight().toDateTime();
String formattedLastNightMidnight = fmt.print(lastNightMidnight);
textViewAwayFrom.setText(formattedLastNightMidnight);
DateTime todayNoon = new DateTime().toDateMidnight().plus(43300000L).toDateTime();
String formattedTodayNoon = fmt.print(todayNoon);
textViewAwayTo.setText(formattedTodayNoon);
Log.e(TAG, "lastNightMidnight = " + lastNightMidnight + " todayNoon = " + todayNoon);发布于 2014-05-02 11:05:33
DateMidnight,因为它是不推荐的。plusHours(12),因为您不想做算术,而只是设置一个小时的一天。最好的方法是(参见javadoc):
DateTime dt;
DateTime noon = dt.withHourOfDay(12);发布于 2014-05-02 10:06:54
DateTime todayNoon = new DateTime().toDateMidnight().toDateTime().plusHours(12);https://stackoverflow.com/questions/23425172
复制相似问题