添加注释

This commit is contained in:
zhouxy108 2024-11-19 21:59:03 +08:00
parent 3f0c14f2d9
commit 8d24d8de23

View File

@ -67,6 +67,8 @@ public class DateTimeTools {
return DATE_TIME_FORMATTER_CACHE.getUnchecked(pattern); return DATE_TIME_FORMATTER_CACHE.getUnchecked(pattern);
} }
// #region - toString
/** /**
* 将日期时间转换为指定格式的字符串 * 将日期时间转换为指定格式的字符串
* *
@ -103,6 +105,10 @@ public class DateTimeTools {
return toString(pattern, dateTime); return toString(pattern, dateTime);
} }
// #endregion
// #region - nowStr
/** /**
* 指定格式返回当前时间戳对应的字符串 * 指定格式返回当前时间戳对应的字符串
* *
@ -124,7 +130,9 @@ public class DateTimeTools {
return toString(pattern, Instant.now().atZone(zone)); return toString(pattern, Instant.now().atZone(zone));
} }
// toDate // #endregion
// #region - toDate
/** /**
* 将时间戳转换为 {@link Date} 对象 * 将时间戳转换为 {@link Date} 对象
@ -189,7 +197,9 @@ public class DateTimeTools {
return Date.from(ZonedDateTime.of(localDate, localTime, zone).toInstant()); return Date.from(ZonedDateTime.of(localDate, localTime, zone).toInstant());
} }
// toInstant // #endregion
// #region - toInstant
/** /**
* 将时间戳转换为 {@link Instant} 对象 * 将时间戳转换为 {@link Instant} 对象
@ -244,7 +254,9 @@ public class DateTimeTools {
return ZonedDateTime.of(localDateTime, zone).toInstant(); return ZonedDateTime.of(localDateTime, zone).toInstant();
} }
// toZonedDateTime // #endregion
// #region - toZonedDateTime
/** /**
* 获取时间戳在指定时区的地区时间 * 获取时间戳在指定时区的地区时间
@ -338,7 +350,9 @@ public class DateTimeTools {
return ZonedDateTime.of(localDateTime, zone); return ZonedDateTime.of(localDateTime, zone);
} }
// toLocalDateTime // #endregion
// #region - toLocalDateTime
/** /**
* 获取时间戳在指定时区的地区时间 * 获取时间戳在指定时区的地区时间
@ -406,9 +420,11 @@ public class DateTimeTools {
return LocalDateTime.ofInstant(zonedDateTime.toInstant(), zone); return LocalDateTime.ofInstant(zonedDateTime.toInstant(), zone);
} }
// #endregion
// ==================== // ====================
// toJodaInstant // #region - toJodaInstant
/** /**
* {@link java.time.Instant} 转换为 {@link org.joda.time.Instant} * {@link java.time.Instant} 转换为 {@link org.joda.time.Instant}
@ -441,7 +457,9 @@ public class DateTimeTools {
return toJodaInstant(java.time.ZonedDateTime.of(localDateTime, zone)); return toJodaInstant(java.time.ZonedDateTime.of(localDateTime, zone));
} }
// toJavaInstant // #endregion
// #region - toJavaInstant
/** /**
* {@link org.joda.time.Instant} 对象转换为 {@link java.time.Instant} 对象 * {@link org.joda.time.Instant} 对象转换为 {@link java.time.Instant} 对象
@ -479,7 +497,9 @@ public class DateTimeTools {
return toJavaInstant(localDateTime.toDateTime(zone)); return toJavaInstant(localDateTime.toDateTime(zone));
} }
// toJodaDateTime // #endregion
// #region - toJodaDateTime
/** /**
* Java 中表示日期时间的 {@link java.time.ZonedDateTime} 对象 * Java 中表示日期时间的 {@link java.time.ZonedDateTime} 对象
@ -506,7 +526,7 @@ public class DateTimeTools {
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 = toJodaTime(zone); org.joda.time.DateTimeZone dateTimeZone = toJodaZone(zone);
return toJodaInstant(ZonedDateTime.of(localDateTime, zone).toInstant()).toDateTime(dateTimeZone); return toJodaInstant(ZonedDateTime.of(localDateTime, zone).toInstant()).toDateTime(dateTimeZone);
} }
@ -520,11 +540,13 @@ public class DateTimeTools {
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 = toJodaTime(zone); org.joda.time.DateTimeZone dateTimeZone = toJodaZone(zone);
return toJodaInstant(instant).toDateTime(dateTimeZone); return toJodaInstant(instant).toDateTime(dateTimeZone);
} }
// toZonedDateTime // #endregion
// #region - toZonedDateTime
/** /**
* joda-time 中带时区的日期时间转换为 java.time 中带时区的日期时间 * joda-time 中带时区的日期时间转换为 java.time 中带时区的日期时间
@ -568,7 +590,9 @@ public class DateTimeTools {
return toJavaInstant(instant).atZone(zone); return toJavaInstant(instant).atZone(zone);
} }
// toJodaLocalDateTime // #endregion
// #region - toJodaLocalDateTime
/** /**
* {@link java.time.LocalDateTime} 转换为 {@link org.joda.time.LocalDateTime} * {@link java.time.LocalDateTime} 转换为 {@link org.joda.time.LocalDateTime}
@ -578,11 +602,13 @@ public class DateTimeTools {
*/ */
public static org.joda.time.LocalDateTime toJodaLocalDateTime(java.time.LocalDateTime localDateTime) { public static org.joda.time.LocalDateTime toJodaLocalDateTime(java.time.LocalDateTime localDateTime) {
java.time.ZoneId javaZone = java.time.ZoneId.systemDefault(); java.time.ZoneId javaZone = java.time.ZoneId.systemDefault();
org.joda.time.DateTimeZone jodaZone = toJodaTime(javaZone); org.joda.time.DateTimeZone jodaZone = toJodaZone(javaZone);
return toJodaInstant(localDateTime, javaZone).toDateTime(jodaZone).toLocalDateTime(); return toJodaInstant(localDateTime, javaZone).toDateTime(jodaZone).toLocalDateTime();
} }
// toJavaLocalDateTime // #endregion
// #region - toJavaLocalDateTime
/** /**
* {@link org.joda.time.LocalDateTime} 转换为 {@link java.time.LocalDateTime} * {@link org.joda.time.LocalDateTime} 转换为 {@link java.time.LocalDateTime}
@ -596,6 +622,10 @@ public class DateTimeTools {
return toJavaInstant(localDateTime, jodaZone).atZone(javaZone).toLocalDateTime(); return toJavaInstant(localDateTime, jodaZone).atZone(javaZone).toLocalDateTime();
} }
// #endregion
// #region - ZoneId <--> DateTimeZone
/** /**
* 转换 Java API joda-time API 表示时区的对象 * 转换 Java API joda-time API 表示时区的对象
* *
@ -612,11 +642,13 @@ public class DateTimeTools {
* @param zone Java API 中表示时区的对象 * @param zone Java API 中表示时区的对象
* @return joda-time API 中表示时区的对象 * @return joda-time API 中表示时区的对象
*/ */
public static org.joda.time.DateTimeZone toJodaTime(java.time.ZoneId zone) { public static org.joda.time.DateTimeZone toJodaZone(java.time.ZoneId zone) {
return org.joda.time.DateTimeZone.forID(zone.getId()); return org.joda.time.DateTimeZone.forID(zone.getId());
} }
// getQuarter // #endregion
// #region - YearQuarter & Quarter
/** /**
* 获取指定日期所在季度 * 获取指定日期所在季度
@ -679,6 +711,8 @@ public class DateTimeTools {
return YearQuarter.of(date); return YearQuarter.of(date);
} }
// #endregion
/** /**
* 私有构造方法明确标识该常量类的作用 * 私有构造方法明确标识该常量类的作用
*/ */