作者:牛尾巴2010 | 2023-09-11 10:37
1> user8332750..:
public class DateUtils {
/**
* Convert {@link java.time.LocalDate} to {@link org.joda.time.DateTime}
*/
public DateTime toDateTime(LocalDate localDate) {
return new DateTime(DateTimeZone.UTC).withDate(
localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()
).withTime(0, 0, 0, 0);
}
/**
* Convert {@link org.joda.time.DateTime} to {@link java.time.LocalDate}
*/
public LocalDate toLocalDate(DateTime dateTime) {
DateTime dateTimeUtc = dateTime.withZone(DateTimeZone.UTC);
return LocalDate.of(dateTimeUtc.getYear(), dateTimeUtc.getMonthOfYear(), dateTimeUtc.getDayOfMonth());
}
}
.withTime(0,0,0,0)可以替换为.withTimeAtStartOfDay()