forked from plusone/plusone-commons
调整代码。
parent
b1804a5005
commit
6d6ef63b06
|
@ -11,6 +11,8 @@ import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.joda.time.DateTimeZone;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
|
import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.collection.MapWrapper;
|
import xyz.zhouxy.plusone.commons.collection.MapWrapper;
|
||||||
|
@ -223,6 +225,7 @@ public class DateTimeUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================
|
// ====================
|
||||||
|
|
||||||
// toJodaInstant
|
// toJodaInstant
|
||||||
|
|
||||||
public static org.joda.time.Instant toJodaInstant(java.time.Instant instant) {
|
public static org.joda.time.Instant toJodaInstant(java.time.Instant instant) {
|
||||||
|
@ -263,14 +266,14 @@ public class DateTimeUtil {
|
||||||
public static org.joda.time.DateTime toJodaDateTime(
|
public static org.joda.time.DateTime toJodaDateTime(
|
||||||
java.time.LocalDateTime localDateTime,
|
java.time.LocalDateTime localDateTime,
|
||||||
java.time.ZoneId zone) {
|
java.time.ZoneId zone) {
|
||||||
org.joda.time.DateTimeZone dateTimeZone = org.joda.time.DateTimeZone.forID(zone.getId());
|
org.joda.time.DateTimeZone dateTimeZone = toJodaTime(zone);
|
||||||
return toJodaInstant(ZonedDateTime.of(localDateTime, zone).toInstant()).toDateTime(dateTimeZone);
|
return toJodaInstant(ZonedDateTime.of(localDateTime, zone).toInstant()).toDateTime(dateTimeZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static org.joda.time.DateTime toJodaDateTime(
|
public static org.joda.time.DateTime toJodaDateTime(
|
||||||
java.time.Instant instant,
|
java.time.Instant instant,
|
||||||
java.time.ZoneId zone) {
|
java.time.ZoneId zone) {
|
||||||
org.joda.time.DateTimeZone dateTimeZone = org.joda.time.DateTimeZone.forID(zone.getId());
|
org.joda.time.DateTimeZone dateTimeZone = toJodaTime(zone);
|
||||||
return toJodaInstant(instant).toDateTime(dateTimeZone);
|
return toJodaInstant(instant).toDateTime(dateTimeZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,31 +287,39 @@ public class DateTimeUtil {
|
||||||
public static java.time.ZonedDateTime toZonedDateTime(
|
public static java.time.ZonedDateTime toZonedDateTime(
|
||||||
org.joda.time.LocalDateTime localDateTime,
|
org.joda.time.LocalDateTime localDateTime,
|
||||||
org.joda.time.DateTimeZone dateTimeZone) {
|
org.joda.time.DateTimeZone dateTimeZone) {
|
||||||
java.time.ZoneId zone = dateTimeZone.toTimeZone().toZoneId();
|
java.time.ZoneId zone = toJavaZone(dateTimeZone);
|
||||||
return toJavaInstant(localDateTime, dateTimeZone).atZone(zone);
|
return toJavaInstant(localDateTime, dateTimeZone).atZone(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static java.time.ZonedDateTime toZonedDateTime(
|
public static java.time.ZonedDateTime toZonedDateTime(
|
||||||
org.joda.time.Instant instant,
|
org.joda.time.Instant instant,
|
||||||
org.joda.time.DateTimeZone dateTimeZone) {
|
org.joda.time.DateTimeZone dateTimeZone) {
|
||||||
java.time.ZoneId zone = dateTimeZone.toTimeZone().toZoneId();
|
java.time.ZoneId zone = toJavaZone(dateTimeZone);
|
||||||
return toJavaInstant(instant).atZone(zone);
|
return toJavaInstant(instant).atZone(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// toJodaLocalDateTime
|
// toJodaLocalDateTime
|
||||||
|
|
||||||
public static org.joda.time.LocalDateTime toJodaLocalDateTime(java.time.LocalDateTime localDateTime) {
|
public static org.joda.time.LocalDateTime toJodaLocalDateTime(java.time.LocalDateTime localDateTime) {
|
||||||
return toJodaInstant(localDateTime, ZoneId.systemDefault())
|
java.time.ZoneId javaZone = java.time.ZoneId.systemDefault();
|
||||||
.toDateTime(org.joda.time.DateTimeZone.getDefault())
|
org.joda.time.DateTimeZone jodaZone = toJodaTime(javaZone);
|
||||||
.toLocalDateTime();
|
return toJodaInstant(localDateTime, javaZone).toDateTime(jodaZone).toLocalDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
// toJavaLocalDateTime
|
// toJavaLocalDateTime
|
||||||
|
|
||||||
public static java.time.LocalDateTime toJavaLocalDateTime(org.joda.time.LocalDateTime localDateTime) {
|
public static java.time.LocalDateTime toJavaLocalDateTime(org.joda.time.LocalDateTime localDateTime) {
|
||||||
return toJavaInstant(localDateTime, org.joda.time.DateTimeZone.getDefault())
|
org.joda.time.DateTimeZone jodaZone = org.joda.time.DateTimeZone.getDefault();
|
||||||
.atZone(java.time.ZoneId.systemDefault())
|
java.time.ZoneId javaZone = toJavaZone(jodaZone);
|
||||||
.toLocalDateTime();
|
return toJavaInstant(localDateTime, jodaZone).atZone(javaZone).toLocalDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static java.time.ZoneId toJavaZone(org.joda.time.DateTimeZone jodaZone) {
|
||||||
|
return jodaZone.toTimeZone().toZoneId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateTimeZone toJodaTime(java.time.ZoneId zone) {
|
||||||
|
return org.joda.time.DateTimeZone.forID(zone.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private DateTimeUtil() {
|
private DateTimeUtil() {
|
||||||
|
|
Loading…
Reference in New Issue