JodaTime equivalent of DateUtils.truncate()
You can use roundFloorCopy() to mimic DateUtils.truncate
Date truncateMonth = DateUtils.truncate(input, Calendar.MONTH);
-> DateTime truncateMonth = input.dayOfMonth().roundFloorCopy();
Date truncateMinute = DateUtils.truncate(input, Calendar.MINUTE);
-> DateTime truncateMinute = input.minuteOfDay().roundFloorCopy();
Date truncateHourOfDay = DateUtils.truncate(input, Calendar.HOUR_OF_DAY);
-> DateTime truncateHourOfDay = input.hourOfDay().roundFloorCopy()
Use the withMillisOfDay()
method to shorten the syntax.
DateTime startOfMonth = input.withDayOfMonth(1).withMillisOfDay(0);
Take a look at DateMidnight
.
DateTime startOfMonth = new DateTime(new DateMidnight(input.withDayOfMonth(1)));
Update: 2013-08-16 by JodaStephen: Version 2.3 of Joda-Time deprecates DateMidnight
as it was a very bad idea of a class.
So use:
DateTime startOfMonth = input.withDayOfMonth(1).withTimeAtStartOfDay();