You should not use
DateMidnight
because it is deprecated.You should also not use
plusHours(12)
because you don't want to do arithmetic but just set the hour of day.
Best way is (see javadoc):
DateTime dt;
DateTime noon = dt.withHourOfDay(12);
문제
I have 2 DateTime objects. The first i set to midnight just gone, the second i want to set to 12 hours later (noon today).
Both objects are set to midnight just gone. Why is this? I've specified 12 hrs later as a long eg 43300000.
thanks in advance
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);
해결책
You should not use DateMidnight
because it is deprecated.
You should also not use plusHours(12)
because you don't want to do arithmetic but just set the hour of day.
Best way is (see javadoc):
DateTime dt;
DateTime noon = dt.withHourOfDay(12);
다른 팁
DateTime todayNoon = new DateTime().toDateMidnight().toDateTime().plusHours(12);