T - The type of DateTime's valueSerializable, Comparable<DateTime<?>>, Temporal, TemporalAccessorpublic class DateTime<T> extends Object implements Temporal, Comparable<DateTime<?>>, Serializable
DateTime class wraps a value of the Date or Calendar or Instant
or LocalDateTime or OffsetDateTime or ZonedDateTime type. | 限定符和类型 | 字段 | 说明 |
|---|---|---|
private T |
dateTime |
|
private static String |
DT_PARSE_ERROR_MSG_TPL |
Date time parse error massage template
|
private static List<String> |
EXCLUDED_CLASS_NAMES |
excluded classes
|
private Instant |
instant |
An instantaneous point on the time-line.
|
private LocalDateTime |
localDateTime |
The local date-time.
|
private ZoneOffset |
offset |
时区偏移量。
|
private OffsetDateTime |
offsetDateTime |
The date-time with an offset
|
private static long |
serialVersionUID |
|
private static List<Class<?>> |
SUPPORTED_DATETIME |
Supported date time
|
private static String |
SUPPORTED_DATETIME_STRING |
Supported date time string
|
private ZoneId |
zone |
时区。
|
private ZonedDateTime |
zonedDateTime |
The date-time with a time-zone
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
List<DateTime<T>> |
allDaysInThisWeek() |
获取当前日期所在周的所有7天的日期(默认每周的第一天为 星期一)
|
List<DateTime<T>> |
allDaysInThisWeek(DayOfWeek firstDayOfWeek) |
获取当前日期所在周的所有7天的日期
|
int |
compareTo(DateTime<?> otherDT) |
|
private static com.iofairy.tuple.Tuple2<CharSequence,String> |
compatibleFormatter(CharSequence text,
String dtPattern) |
The date time format is compatible with
yyyyMMddHHmmssSSS.NOTE: Java 8 bug: DateTimeFormatter fails on parsing "yyyyMMddHHmmssSSS" |
List<T> |
datesByShift(int shiftTimes,
int amountUnit,
ChronoUnit chronoUnit,
boolean includeCurrentTime) |
从给定的时间,按指定的时间单位,指定的步长偏移时间,返回每次偏移后的所有时间列表
|
List<T> |
datesByShift(int shiftTimes,
ChronoUnit chronoUnit) |
从给定的时间,按指定的时间单位,指定的步长偏移时间,返回每次偏移后的所有时间列表
|
List<T> |
datesByShift(int shiftTimes,
ChronoUnit chronoUnit,
boolean includeCurrentTime) |
从给定的时间,按指定的时间单位,指定的步长偏移时间,返回每次偏移后的所有时间列表
|
List<T> |
datesFromRange(DateTime<?> toDateTime,
int amountUnit,
ChronoUnit chronoUnit,
IntervalType intervalType) |
从给定的时间范围(开始时间,结束时间),按指定的时间单位,指定的步长偏移时间,返回每次偏移后的所有时间列表
|
List<T> |
datesFromRange(DateTime<?> toDateTime,
ChronoUnit chronoUnit) |
从给定的时间范围(开始时间,结束时间),按指定的时间单位,指定的步长偏移时间,返回每次偏移后的所有时间列表
|
List<T> |
datesFromRange(DateTime<?> toDateTime,
ChronoUnit chronoUnit,
IntervalType intervalType) |
从给定的时间范围(开始时间,结束时间),按指定的时间单位,指定的步长偏移时间,返回每次偏移后的所有时间列表
|
int |
daysOfMonth() |
获取某个月的总天数
|
String |
dtDetail() |
详细的 toString
|
DateTime<T> |
dtInThisWeek(DayOfWeek dayOfWeek) |
获取当前日期所在周的任意星期几的日期(默认每周的第一天为 星期一)
|
DateTime<T> |
dtInThisWeek(DayOfWeek firstDayOfWeek,
DayOfWeek dayOfWeek) |
获取当前日期所在周的任意星期几的日期
|
boolean |
equals(Object obj) |
|
DateTime<T> |
fill0(ChronoUnit chronoUnit) |
保留所提供的chronoUnit以及比chronoUnit大的单位的值,填充比 chronoUnit 小的单位的值为 0。
|
DateTime<T> |
fill9(ChronoUnit chronoUnit) |
保留所提供的chronoUnit以及比chronoUnit大的单位的值,填充比 chronoUnit 小的单位的值为 所允许的最大值。
|
DateTime<T> |
firstInThisWeek() |
获取当前日期所在周的第一天(默认每周的第一天为 星期一)
|
DateTime<T> |
firstInThisWeek(DayOfWeek firstDayOfWeek) |
获取当前日期所在周的第一天
|
String |
format(String dtPattern) |
Formats this date-time using the specified DateTime Pattern
|
String |
format(DateTimeFormatter formatter) |
Formats this date-time using the specified formatter
|
(专用程序包) static <T> DateTime<T> |
from(T dateTime) |
|
T |
get() |
Get the copied
dateTime value. |
int |
get(TemporalField field) |
|
private T |
getDateTime(T dt) |
|
int |
getDayOfMonth() |
|
DayOfWeek |
getDayOfWeek() |
|
int |
getDayOfYear() |
|
int |
getHour() |
|
Instant |
getInstant() |
|
LocalDateTime |
getLocalDateTime() |
|
long |
getLong(TemporalField field) |
|
int |
getMicros() |
|
int |
getMillis() |
|
int |
getMinute() |
|
Month |
getMonth() |
|
int |
getMonthValue() |
|
int |
getNano() |
|
ZoneOffset |
getOffset() |
|
OffsetDateTime |
getOffsetDateTime() |
|
int |
getSecond() |
|
int |
getYear() |
|
ZoneId |
getZone() |
|
ZonedDateTime |
getZonedDateTime() |
|
boolean |
in(DateTime<?> startDT,
DateTime<?> endDT,
IntervalType intervalType) |
判断当前 DateTime 是否在提供的两个 DateTime 之间
|
boolean |
isAfter(DateTime<?> otherDT) |
|
boolean |
isAfterOrEquals(DateTime<?> otherDT) |
|
boolean |
isBefore(DateTime<?> otherDT) |
|
boolean |
isBeforeOrEquals(DateTime<?> otherDT) |
|
boolean |
isSupported(TemporalField field) |
|
boolean |
isSupported(TemporalUnit unit) |
|
DateTime<T> |
lastInThisWeek() |
获取当前日期所在周的最后一天(默认每周的第一天为 星期一)
|
DateTime<T> |
lastInThisWeek(DayOfWeek firstDayOfWeek) |
获取当前日期所在周的最后一天
|
DateTime<T> |
minus(long amount,
TemporalUnit unit) |
对 DateTime 进行增减操作。
|
DateTime<T> |
minus(TemporalAmount amountToSubtract) |
对 DateTime 进行增减操作。
|
DateTime<T> |
minusDays(long days) |
|
DateTime<T> |
minusHours(long hours) |
|
DateTime<T> |
minusMicros(long micros) |
|
DateTime<T> |
minusMillis(long millis) |
|
DateTime<T> |
minusMinutes(long minutes) |
|
DateTime<T> |
minusMonths(long months) |
|
DateTime<T> |
minusNanos(long nanos) |
|
DateTime<T> |
minusSeconds(long seconds) |
|
DateTime<T> |
minusYears(long years) |
|
static DateTime<LocalDateTime> |
now() |
Get current
LocalDateTime |
static DateTime<Date> |
nowDate() |
Get current
Date |
static DateTime<Instant> |
nowInstant() |
Get current
Instant |
static <T> DateTime<T> |
of(T dateTime) |
|
static DateTime<LocalDateTime> |
parse(CharSequence text) |
Obtains an instance of
DateTime<LocalDateTime> by intelligently determining the format of a time text. |
static DateTime<LocalDateTime> |
parse(CharSequence text,
String dtPattern) |
|
static DateTime<LocalDateTime> |
parse(CharSequence text,
DateTimeFormatter formatter) |
Obtains an instance of
DateTime<LocalDateTime> from a text string using a specific formatter. |
static DateTime<Date> |
parseDate(CharSequence text) |
Obtains an instance of
DateTime<Date> from a text intelligently. |
static DateTime<Date> |
parseDate(CharSequence text,
String dtPattern) |
|
static DateTime<Date> |
parseDate(CharSequence text,
String dtPattern,
ZoneId zoneId) |
|
static DateTime<Date> |
parseDate(CharSequence text,
DateTimeFormatter formatter) |
|
static DateTime<Date> |
parseDate(CharSequence text,
DateTimeFormatter formatter,
ZoneId zoneId) |
从 时间格式串 中获取
DateTime<Date> |
static DateTime<Date> |
parseDate(CharSequence text,
ZoneId zoneId) |
Obtains an instance of
DateTime<Date> from a text string using a formatter that is intelligently selected through the system. |
DateTime<T> |
plus(long amount,
TemporalUnit unit) |
对 DateTime 进行增减操作。
|
DateTime<T> |
plus(TemporalAmount amountToAdd) |
对 DateTime 进行增减操作。
|
DateTime<T> |
plusDays(long days) |
|
DateTime<T> |
plusHours(long hours) |
|
DateTime<T> |
plusMicros(long micros) |
|
DateTime<T> |
plusMillis(long millis) |
|
DateTime<T> |
plusMinutes(long minutes) |
|
DateTime<T> |
plusMonths(long months) |
|
DateTime<T> |
plusNanos(long nanos) |
|
DateTime<T> |
plusSeconds(long seconds) |
|
DateTime<T> |
plusYears(long years) |
|
DateTime<T> |
round(ChronoUnit chronoUnit,
RoundingDT roundingDT) |
对 DateTime 进行取整
|
DateTime<T> |
roundTime(ChronoUnit chronoUnit,
int amountUnit,
RoundingDT roundingDT) |
对 DateTime 的 时,分,秒 进行取整。
|
Calendar |
toCalendar(ZoneId zoneId) |
将 DateTime 转为指定时区的 Calendar。
|
(专用程序包) Calendar |
toCalendar(Calendar calendar,
ZonedDateTime zonedDateTime) |
ZonedDateTime 转成 Calendar,且返回的 Calendar 与参数 calendar 相同类型
|
Date |
toDate() |
|
Calendar |
toDefaultCalendar() |
将 DateTime 转为
TZ.DEFAULT_ZONE 时区的 Calendar |
OffsetDateTime |
toDefaultOffsetDT() |
将 DateTime 转为
DateTimes.defaultOffset() 时区的 OffsetDateTime |
ZonedDateTime |
toDefaultZonedDT() |
将 DateTime 转为
TZ.DEFAULT_ZONE 时区的 ZonedDateTime |
long |
toEpochMilli() |
|
long |
toEpochSecond() |
|
Instant |
toInstant() |
将 DateTime 转为
Instant。 |
LocalDateTime |
toLocalDateTime() |
将 DateTime 转为
LocalDateTime |
OffsetDateTime |
toOffsetDT(ZoneOffset zoneOffset) |
将 DateTime 转为指定时区的
OffsetDateTime |
String |
toString() |
|
Calendar |
toUTCCalendar() |
将 DateTime 转为
TZ.UTC 时区的 Calendar |
OffsetDateTime |
toUTCOffsetDT() |
将 DateTime 转为
ZoneOffset.UTC 时区的 OffsetDateTime |
ZonedDateTime |
toUTCZonedDT() |
将 DateTime 转为
TZ.UTC 时区的 ZonedDateTime |
private com.iofairy.tuple.Tuple2<Instant,ZonedDateTime> |
toZDTAndInstant() |
|
ZonedDateTime |
toZonedDT(ZoneId zoneId) |
将 DateTime 转为指定时区的
ZonedDateTime |
long |
until(Temporal endExclusive,
TemporalUnit unit) |
|
DateTime<T> |
with(TemporalAdjuster adjuster) |
|
DateTime<T> |
with(TemporalField field,
long newValue) |
|
DateTime<T> |
withDayOfMonth(int dayOfMonth) |
|
DateTime<T> |
withDayOfYear(int dayOfYear) |
|
DateTime<T> |
withHour(int hour) |
|
DateTime<T> |
withMinute(int minute) |
|
DateTime<T> |
withMonth(int month) |
|
DateTime<T> |
withNano(int nanoOfSecond) |
|
DateTime<T> |
withSecond(int second) |
|
DateTime<T> |
withYear(int year) |
query, rangeprivate static final long serialVersionUID
private final T dateTime
dateTime 是 Instant 或 LocalDateTime 类型,所有的计算均选择当前默认时区 TZ.DEFAULT_ZONE 进行计算。dateTime 转成 ZonedDateTime 类型之后,再构造 DateTime<T> 对象private final LocalDateTime localDateTime
private final ZoneOffset offset
Instant 类型时,时区偏移量采用当前默认时区的偏移量;LocalDateTime 类型时,时区偏移量采用当前默认时区的偏移量。private final ZoneId zone
Instant 类型时,时区采用当前默认时区 TZ.DEFAULT_ZONE;LocalDateTime 类型时,时区采用当前默认时区 TZ.DEFAULT_ZONE。private final Instant instant
private final ZonedDateTime zonedDateTime
private final OffsetDateTime offsetDateTime
private static final String SUPPORTED_DATETIME_STRING
public DateTime(T dateTime)
private DateTime(T dateTime, boolean checkValue)
public static <T> DateTime<T> of(T dateTime)
static <T> DateTime<T> from(T dateTime)
public static DateTime<LocalDateTime> now()
LocalDateTimeDateTime<LocalDateTime>public static DateTime<Instant> nowInstant()
InstantDateTime<Instant>public LocalDateTime getLocalDateTime()
public ZoneOffset getOffset()
public ZoneId getZone()
public Instant getInstant()
public ZonedDateTime getZonedDateTime()
public OffsetDateTime getOffsetDateTime()
private com.iofairy.tuple.Tuple2<Instant,ZonedDateTime> toZDTAndInstant()
public ZonedDateTime toUTCZonedDT()
TZ.UTC 时区的 ZonedDateTimepublic ZonedDateTime toDefaultZonedDT()
TZ.DEFAULT_ZONE 时区的 ZonedDateTimepublic ZonedDateTime toZonedDT(ZoneId zoneId)
ZonedDateTimezoneId - zoneId. 当 zoneId为null时,且 dateTime 是 ZonedDateTime 或 OffsetDateTime 或 Calendar 类型时,
默认采用dateTime自己的时区;否则,默认采用TZ.DEFAULT_ZONEpublic OffsetDateTime toUTCOffsetDT()
ZoneOffset.UTC 时区的 OffsetDateTimepublic OffsetDateTime toDefaultOffsetDT()
DateTimes.defaultOffset() 时区的 OffsetDateTimepublic OffsetDateTime toOffsetDT(ZoneOffset zoneOffset)
OffsetDateTimezoneOffset - zoneOffset. 当 zoneOffset为null时,且 datetime 是 OffsetDateTime 或 ZonedDateTime 或 Calendar 类型时,
默认采用datetime自己的时区偏移;否则,默认采用DateTimes.defaultOffset()时区偏移public Calendar toDefaultCalendar()
TZ.DEFAULT_ZONE 时区的 Calendarpublic Calendar toCalendar(ZoneId zoneId)
zoneId - 时区。当 zoneId为null时,且 dateTime 是 ZonedDateTime 或 OffsetDateTime 或 Calendar 类型时,
默认采用dateTime自己的时区;否则,默认采用TZ.DEFAULT_ZONECalendar toCalendar(Calendar calendar, ZonedDateTime zonedDateTime)
calendar - calendar,用于指示返回的 Calendar 的类型zonedDateTime - zonedDateTimepublic LocalDateTime toLocalDateTime()
LocalDateTimepublic Date toDate()
public Instant toInstant()
Instant。LocalDateTime 转为 Instant 时,以 默认时区 的 LocalDateTime 转为 Instant。public DateTime<T> plus(long amount, TemporalUnit unit)
public DateTime<T> plus(TemporalAmount amountToAdd)
public DateTime<T> minus(long amount, TemporalUnit unit)
public DateTime<T> minus(TemporalAmount amountToSubtract)
public DateTime<T> with(TemporalAdjuster adjuster)
public DateTime<T> with(TemporalField field, long newValue)
public int get(TemporalField field)
get 在接口中 TemporalAccessorpublic int getYear()
public int getMonthValue()
public Month getMonth()
public int getDayOfYear()
public int getDayOfMonth()
public DayOfWeek getDayOfWeek()
public int getHour()
public int getMinute()
public int getSecond()
public int getMillis()
public int getMicros()
public int getNano()
public DateTime<T> round(ChronoUnit chronoUnit, RoundingDT roundingDT)
chronoUnit - 按此时间单位作为取整后的精度roundingDT - 取整类型,值为null默认为:RoundingDT.FLOORpublic DateTime<T> roundTime(ChronoUnit chronoUnit, int amountUnit, RoundingDT roundingDT)
chronoUnit - 按此时间单位作为取整后的精度amountUnit - 时间步长(不分正负)roundingDT - 取整类型,值为null默认为:RoundingDT.FLOORpublic List<T> datesByShift(int shiftTimes, int amountUnit, ChronoUnit chronoUnit, boolean includeCurrentTime)
shiftTimes - 偏移的次数,负数:则时间往前偏移;正数:则时间往后偏移amountUnit - 偏移的步长(不分正负)chronoUnit - 时间单位includeCurrentTime - 最后列表是否包含 fromDatepublic List<T> datesByShift(int shiftTimes, ChronoUnit chronoUnit, boolean includeCurrentTime)
shiftTimes - 偏移的次数,负数:则时间往前偏移;正数:则时间往后偏移chronoUnit - 时间单位includeCurrentTime - 最后列表是否包含 fromDatepublic List<T> datesByShift(int shiftTimes, ChronoUnit chronoUnit)
shiftTimes - 偏移的次数,负数:则时间往前偏移;正数:则时间往后偏移chronoUnit - 时间单位public List<T> datesFromRange(DateTime<?> toDateTime, int amountUnit, ChronoUnit chronoUnit, IntervalType intervalType)
toDateTime - 结束的时间amountUnit - 偏移的步长(不分正负)chronoUnit - 时间单位intervalType - 区间类型public List<T> datesFromRange(DateTime<?> toDateTime, ChronoUnit chronoUnit, IntervalType intervalType)
toDateTime - 结束的时间chronoUnit - 时间单位intervalType - 区间类型public List<T> datesFromRange(DateTime<?> toDateTime, ChronoUnit chronoUnit)
toDateTime - 结束的时间chronoUnit - 时间单位public DateTime<T> fill0(ChronoUnit chronoUnit)
chronoUnit - 时间单位public DateTime<T> fill9(ChronoUnit chronoUnit)
chronoUnit - 时间单位public int daysOfMonth()
public String format(String dtPattern)
dtPattern - DateTime Patternpublic String format(DateTimeFormatter formatter)
formatter - DateTimeFormatterpublic static DateTime<LocalDateTime> parse(CharSequence text)
DateTime<LocalDateTime> by intelligently determining the format of a time text.text - the text to parse, not nullDateTime<LocalDateTime>DateTimeParseException - if the text cannot be parsedpublic static DateTime<LocalDateTime> parse(CharSequence text, String dtPattern)
public static DateTime<LocalDateTime> parse(CharSequence text, DateTimeFormatter formatter)
DateTime<LocalDateTime> from a text string using a specific formatter.
The text is parsed using the formatter, returning a date-time.
text - the text to parse, not nullformatter - the formatter to use, not nullDateTimeParseException - if the text cannot be parsedpublic static DateTime<Date> parseDate(CharSequence text)
DateTime<Date> from a text intelligently.text - the text to parse, not nullDateTime<Date>DateTimeParseException - if the text cannot be parsedpublic static DateTime<Date> parseDate(CharSequence text, ZoneId zoneId)
DateTime<Date> from a text string using a formatter that is intelligently selected through the system.text - the text to parse, not nullzoneId - zoneIdDateTime<Date>DateTimeParseException - if the text cannot be parsedpublic static DateTime<Date> parseDate(CharSequence text, String dtPattern)
public static DateTime<Date> parseDate(CharSequence text, String dtPattern, ZoneId zoneId)
public static DateTime<Date> parseDate(CharSequence text, DateTimeFormatter formatter)
public static DateTime<Date> parseDate(CharSequence text, DateTimeFormatter formatter, ZoneId zoneId)
DateTime<Date>text - 时间格式串formatter - formatterzoneId - 时间格式串所属的时区。null 则为 默认时区。DateTime<Date>private static com.iofairy.tuple.Tuple2<CharSequence,String> compatibleFormatter(CharSequence text, String dtPattern)
yyyyMMddHHmmssSSS.text - date time stringdtPattern - date time patterntext and dtPatternpublic long until(Temporal endExclusive, TemporalUnit unit)
public boolean isSupported(TemporalUnit unit)
isSupported 在接口中 Temporalpublic boolean isSupported(TemporalField field)
isSupported 在接口中 TemporalAccessorpublic long getLong(TemporalField field)
getLong 在接口中 TemporalAccessorpublic DateTime<T> dtInThisWeek(DayOfWeek dayOfWeek)
dayOfWeek - 取星期几的日期public DateTime<T> dtInThisWeek(DayOfWeek firstDayOfWeek, DayOfWeek dayOfWeek)
firstDayOfWeek - 指定每周的第一天是星期几dayOfWeek - 取星期几的日期public DateTime<T> firstInThisWeek()
public DateTime<T> firstInThisWeek(DayOfWeek firstDayOfWeek)
firstDayOfWeek - 指定每周的第一天是星期几public DateTime<T> lastInThisWeek()
public DateTime<T> lastInThisWeek(DayOfWeek firstDayOfWeek)
firstDayOfWeek - 指定每周的第一天是星期几public List<DateTime<T>> allDaysInThisWeek()
public List<DateTime<T>> allDaysInThisWeek(DayOfWeek firstDayOfWeek)
firstDayOfWeek - 指定每周的第一天是星期几public boolean isBefore(DateTime<?> otherDT)
public boolean isAfter(DateTime<?> otherDT)
public boolean isBeforeOrEquals(DateTime<?> otherDT)
public boolean isAfterOrEquals(DateTime<?> otherDT)
public boolean in(DateTime<?> startDT, DateTime<?> endDT, IntervalType intervalType)
startDT - 开始 DateTimeendDT - 结束 DateTimeintervalType - 区间类型。true,否则返回 falsecom.iofairy.except.UnexpectedParameterException - if endDT is before startDTpublic long toEpochSecond()
public long toEpochMilli()
public int compareTo(DateTime<?> otherDT)
compareTo 在接口中 Comparable<T>public String dtDetail()
Copyright © 2023. All rights reserved.