public final class DateTimes extends Object
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
private static List<Class<? extends Temporal>> |
SUPPORTED_TEMPORAL_FOR_DOM |
Supported temporal for
daysOfMonth methods. |
| 构造器 | 说明 |
|---|---|
DateTimes() |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static Calendar |
clone(Calendar calendar) |
克隆一个 Calendar
|
static Date |
clone(Date date) |
克隆一个 Date
|
static com.iofairy.tuple.Tuple2<Integer,Integer> |
daysBetween(DayOfWeek startDayOfWeek,
DayOfWeek endDayOfWeek) |
获取两个星期几之间相差的天数。
|
static int |
daysOfMonth(int year,
int month) |
获取某个月的总天数
|
static int |
daysOfMonth(Temporal temporal) |
获取某个月的总天数
|
static Date |
defaultDateToTZ(Date date,
ZoneId zoneId) |
Convert local Date object to another timezone
将默认Date时间对象转成另一个时区的Date对象 |
static LocalDateTime |
defaultLocalDTToTZ(LocalDateTime localDateTime,
ZoneId zoneId) |
Convert local LocalDateTime object to another timezone
将默认LocalDateTime时间对象转成另一个时区的LocalDateTime对象 |
static ZoneOffset |
defaultOffset() |
获取当前系统当前时间的时区偏移
ZoneOffset。 |
static DayOfWeek |
getLastDayOfWeek(DayOfWeek firstDayOfWeek) |
通过每周的第一天,计算每周的最后一天
|
static Map<ZoneOffset,List<ZoneId>> |
getOffsetZoneIds() |
获取当前时间的 ZoneOffset 以及对应的 ZoneId 列表。
|
static List<ZoneId> |
getZoneIds(ZoneOffset zoneOffset) |
通过zoneOffset获取对应的ZoneId集合
|
static List<String> |
hourMinutesOfDay(boolean withZeroSecond,
String separator) |
一天中的所有分钟
|
static List<String> |
hoursOfDay(int withMode,
String separator) |
使用指定格式返回一天中的24小时
|
static List<String> |
hoursOfDay(String day,
int withMode) |
使用指定格式返回一天中的24小时
|
static List<String> |
hoursOfDay(String day,
int withMode,
String separator) |
使用指定格式返回一天中的24小时
|
static List<String> |
minutesOfHour(String hour,
boolean withZeroSecond,
String separator) |
某个指定小时的所有分钟
|
static List<String> |
secondsOfMinute(String minute,
String separator) |
某个指定分钟的所有秒
|
static Calendar |
toCalendar(Instant instant) |
Instant 转成 Calendar
|
static Calendar |
toCalendar(OffsetDateTime offsetDateTime) |
OffsetDateTime 转成 Calendar
|
static Calendar |
toCalendar(ZonedDateTime zonedDateTime) |
ZonedDateTime 转成 Calendar
|
static Calendar |
toCalendar(Calendar calendar,
ZoneId zoneId) |
Calendar 转成 其他时区,返回新的 Calendar 对象
|
static Calendar |
toCalendar(Date date,
ZoneId zoneId) |
Date 转 Calendar
|
static BigInteger |
toMicros(long amount,
ChronoUnit chronoUnit) |
将某个时间类型转为微秒
|
static BigInteger |
toNanos(long amount,
ChronoUnit chronoUnit) |
将某个时间类型转为纳秒
|
static ZonedDateTime |
toZonedDT(Calendar calendar,
ZoneId toZoneId) |
将 calendar 转成与之相同时区的 ZonedDateTime,或指定时区的
toZoneId ZonedDateTime。 |
static Date |
tzDateToTZ(Date date,
ZoneId fromZoneId,
ZoneId toZoneId) |
Convert fromZoneId Date to toZoneId
将Date对象从一个时区转成另一个时区的Date对象 |
static ZonedDateTime |
tzDateToZonedDT(Date date,
ZoneId fromZoneId,
ZoneId toZoneId) |
Convert date from fromZoneId Date to toZoneId ZonedDateTime
将 一个时区 的 Date 转成另一个时区的 ZonedDateTime |
static LocalDateTime |
tzLocalDTToTZ(LocalDateTime localDateTime,
ZoneId fromZoneId,
ZoneId toZoneId) |
Convert fromZoneId LocalDateTime to toZoneId
将LocalDateTime对象从一个时区转成另一个时区的LocalDateTime对象 |
static ZoneOffset |
zoneOffset(String zoneIdName) |
通过ZoneId名称获取当前时间的时区偏移
ZoneOffset。 |
static ZoneOffset |
zoneOffset(ZoneId zoneId) |
通过ZoneId获取当前时间的时区偏移
ZoneOffset。 |
static ZoneOffset |
zoneOffset(ZoneId zoneId,
Instant instant) |
根据指定 zoneId 与 instant 获取当时的时区偏移
ZoneOffset。 |
static ZoneOffset |
zoneOffset(Calendar calendar) |
获取 calendar 的时区偏移
ZoneOffset |
public static Map<ZoneOffset,List<ZoneId>> getOffsetZoneIds()
public static List<ZoneId> getZoneIds(ZoneOffset zoneOffset)
zoneOffset - zoneOffsetpublic static ZoneOffset defaultOffset()
ZoneOffset。
由于有些地区有夏令时,不同时间结果会不一样。所以需要实时获取。public static ZoneOffset zoneOffset(String zoneIdName)
ZoneOffset。zoneIdName - ZoneId名称public static ZoneOffset zoneOffset(ZoneId zoneId)
ZoneOffset。zoneId - ZoneIdpublic static ZoneOffset zoneOffset(ZoneId zoneId, Instant instant)
ZoneOffset。ZoneOffset会不一样。所以需要根据指定的 instant 获取。zoneId - zoneIdinstant - instantpublic static ZoneOffset zoneOffset(Calendar calendar)
ZoneOffsetcalendar - calendarpublic static Date defaultDateToTZ(Date date, ZoneId zoneId)
date - datezoneId - zoneIdpublic static Date tzDateToTZ(Date date, ZoneId fromZoneId, ZoneId toZoneId)
date - datefromZoneId - fromZoneId. 当 fromZoneId 为 null时,采用 TZ.DEFAULT_ZONEtoZoneId - toZoneId. 当 toZoneId 为 null时,采用 TZ.DEFAULT_ZONEpublic static LocalDateTime defaultLocalDTToTZ(LocalDateTime localDateTime, ZoneId zoneId)
localDateTime - LocalDateTimezoneId - zoneIdpublic static LocalDateTime tzLocalDTToTZ(LocalDateTime localDateTime, ZoneId fromZoneId, ZoneId toZoneId)
localDateTime - LocalDateTimefromZoneId - fromZoneId. 当 fromZoneId 为 null时,采用 TZ.DEFAULT_ZONEtoZoneId - toZoneId. 当 toZoneId 为 null时,采用 TZ.DEFAULT_ZONEpublic static ZonedDateTime tzDateToZonedDT(Date date, ZoneId fromZoneId, ZoneId toZoneId)
date - datefromZoneId - fromZoneId. 当 fromZoneId 为 null时,采用 TZ.DEFAULT_ZONEtoZoneId - toZoneId. 当 toZoneId 为 null时,采用 TZ.DEFAULT_ZONEpublic static ZonedDateTime toZonedDT(Calendar calendar, ZoneId toZoneId)
toZoneId ZonedDateTime。calendar - calendartoZoneId - 指定转换的目标时区public static Calendar toCalendar(Date date, ZoneId zoneId)
date - datezoneId - 时区。当前 zoneId 为 null 时,采用默认时区。public static Calendar toCalendar(Calendar calendar, ZoneId zoneId)
calendar - calendarzoneId - 时区。当前 zoneId 为 null 时,采用默认时区。public static Calendar toCalendar(Instant instant)
instant - instantpublic static Calendar toCalendar(ZonedDateTime zonedDateTime)
zonedDateTime - zonedDateTimepublic static Calendar toCalendar(OffsetDateTime offsetDateTime)
offsetDateTime - offsetDateTimepublic static Calendar clone(Calendar calendar)
calendar - calendarpublic static BigInteger toMicros(long amount, ChronoUnit chronoUnit)
amount - 时间量chronoUnit - 时间单位public static BigInteger toNanos(long amount, ChronoUnit chronoUnit)
amount - 时间量chronoUnit - 时间单位public static int daysOfMonth(int year,
int month)
year - 当前年份month - 当前月份public static int daysOfMonth(Temporal temporal)
temporal - temporalpublic static com.iofairy.tuple.Tuple2<Integer,Integer> daysBetween(DayOfWeek startDayOfWeek, DayOfWeek endDayOfWeek)
startDayOfWeek - 开始的星期几endDayOfWeek - 结束的星期几Tuple2(previousDays, nextDays) 值。public static DayOfWeek getLastDayOfWeek(DayOfWeek firstDayOfWeek)
firstDayOfWeek - 每周第一天public static List<String> hoursOfDay(int withMode, String separator)
withMode - 0: 只返回小时;1:返回小时并在末尾拼接上00分钟;2:返回小时并在末尾拼接00分钟和00秒separator - 当 withMode 为 1,2时,需要指定分隔符。如果为 null,则默认采用 ""public static List<String> hoursOfDay(String day, int withMode)
day - 指定的天withMode - 0: 只返回小时;1:返回小时并在末尾拼接上00分钟;2:返回小时并在末尾拼接00分钟和00秒public static List<String> hoursOfDay(String day, int withMode, String separator)
day - 指定的天withMode - 0: 只返回小时;1:返回小时并在末尾拼接上00分钟;2:返回小时并在末尾拼接00分钟和00秒separator - 当 withMode 为 1,2时,需要指定分隔符。如果为 null,则默认采用 ""public static List<String> hourMinutesOfDay(boolean withZeroSecond, String separator)
withZeroSecond - 是否在末尾拼接00秒separator - 拼接时采用的分隔符。如果为 null,则默认采用 ""public static List<String> minutesOfHour(String hour, boolean withZeroSecond, String separator)
hour - 时。如果为 null,则默认采用 ""withZeroSecond - 是否在末尾拼接00秒separator - 拼接时采用的分隔符。如果为 null,则默认采用 ""Copyright © 2023. All rights reserved.