Package org.aoju.bus.core.date
Class Converter
java.lang.Object
org.aoju.bus.core.date.Formatter
org.aoju.bus.core.date.Converter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CalendartoCalendar(long millis) 转换为Calendar对象static CalendartoCalendar(Date date) 将Date转换为Calendarstatic CalendartoCalendar(Date date, TimeZone timeZone) 将Date转换为Calendar.static CalendartoCalendar(XMLGregorianCalendar calendar) 转换为Calendar对象static DatetoDate(long epochMilli) 时间戳epochMilli毫秒转Datestatic DateInstant转Datestatic DateLocalDate转Datestatic DatetoDate(LocalDateTime localDateTime) LocalDateTime转Datestatic DateLocalTime转Date 以当天的日期+LocalTime组成新的LocalDateTime转换为Datestatic DateYearMonth转Date 注意dayOfMonth范围:1到31之间,最大值根据月份确定特殊情况,如2月闰年29,非闰年28 如果要转换为当月最后一天,可以使用下面方法:toDateEndOfMonth(YearMonth)static DatetoDate(ZonedDateTime zonedDateTime) ZonedDateTime转Date 注意时间对应的时区和默认时区差异static DatetoDateEndOfMonth(YearMonth yearMonth) YearMonth转Date,转换为当月最后一天static DatetoDateStartOfMonth(YearMonth yearMonth) YearMonth转Date,转换为当月第一天static longtoEpochMilli(Timestamp timestamp) Timestamp转时间戳 从1970-01-01T00:00:00Z开始的毫秒值static longtoEpochMilli(Instant instant) Instant转时间戳 从1970-01-01T00:00:00Z开始的毫秒值static longtoEpochMilli(LocalDate localDate) LocalDate转时间戳 从1970-01-01T00:00:00Z开始的毫秒值static longtoEpochMilli(LocalDateTime localDateTime) LocalDateTime转时间戳 从1970-01-01T00:00:00Z开始的毫秒值static longtoEpochMilli(TemporalAccessor temporalAccessor) static longtoEpochMilli(ZonedDateTime zonedDateTime) ZonedDateTime转时间戳,注意,zonedDateTime时区必须和当前系统时区一致,不然会出现问题 从1970-01-01T00:00:00Z开始的毫秒值static longtoEpochMilli(Date date) Date转时间戳 从1970-01-01T00:00:00Z开始的毫秒值static InstanttoInstant(long epochMilli) 时间戳epochMilli毫秒转Instantstatic InstantTimestamp转Instantstatic InstantLocalDate转Instantstatic InstanttoInstant(LocalDateTime localDateTime) LocalDateTime转Instantstatic InstantLocalTime转Instant 以当天的日期+LocalTime组成新的LocalDateTime转换为Instantstatic InstanttoInstant(TemporalAccessor temporalAccessor) Date对象转换为Instant对象static InstanttoInstant(ZonedDateTime zonedDateTime) ZonedDateTime转Instant 注意,zonedDateTime时区必须和当前系统时区一致,不然会出现问题static InstantCalendarInstant对象static InstantDate转Instantstatic LocalDatetoLocalDate(long epochMilli) 时间戳epochMilli毫秒转LocalDatestatic LocalDatetoLocalDate(Instant instant) Instant转LocalDatestatic LocalDatetoLocalDate(LocalDateTime localDateTime) LocalDateTime转LocalDatestatic LocalDatetoLocalDate(TemporalAccessor temporal) temporal转LocalDatestatic LocalDatetoLocalDate(YearMonth yearMonth, int dayOfMonth) YearMonth转LocalDate 注意dayOfMonth范围:1到31之间,最大值根据月份确定特殊情况,如2月闰年29,非闰年28 如果要转换为当月最后一天,可以使用下面方法:toLocalDateEndOfMonth(YearMonth)static LocalDatetoLocalDate(ZonedDateTime zonedDateTime) ZonedDateTime转LocalDate 注意时间对应的时区和默认时区差异static LocalDatetoLocalDate(Date date) Date转LocalDatestatic LocalDatetoLocalDateEndOfMonth(YearMonth yearMonth) YearMonth转LocalDate,转换为当月最后一天static LocalDatetoLocalDateStartOfMonth(YearMonth yearMonth) YearMonth转LocalDate,转换为当月第一天static LocalDateTimetoLocalDateTime(long epochMilli) 时间戳epochMilli毫秒转LocalDateTimestatic LocalDateTimetoLocalDateTime(Timestamp timestamp) Timestamp转LocalDateTimestatic LocalDateTimetoLocalDateTime(Instant instant) Instant转LocalDateTimestatic LocalDateTimetoLocalDateTime(LocalDate localDate) LocalDate转LocalDateTimestatic LocalDateTimetoLocalDateTime(LocalTime localTime) LocalTime转LocalDateTime 以当天的日期+LocalTime组成新的LocalDateTimestatic LocalDateTimetoLocalDateTime(TemporalAccessor temporal) temporal转LocalDateTimestatic LocalDateTimetoLocalDateTime(ZonedDateTime zonedDateTime) ZonedDateTime转LocalDateTime 注意时间对应的时区和默认时区差异static LocalDateTimetoLocalDateTime(Date date) Date转LocalDateTimestatic LocalTimetoLocalTime(Instant instant) Instant转LocalTimestatic LocalTimetoLocalTime(LocalDateTime localDateTime) LocalDateTime转LocalTimestatic LocalTimetoLocalTime(TemporalAccessor temporal) temporal转LocalTimestatic LocalTimetoLocalTime(ZonedDateTime zonedDateTime) ZonedDateTime转LocalTime 注意时间对应的时区和默认时区差异static LocalTimetoLocalTime(Date date) Date转LocalTimestatic intHH:mm:ss 时间格式字符串转为秒数static StringtoTime(int seconds) 秒数转为时间格式(HH:mm:ss)static TimestamptoTimestamp(long epochMilli) 时间戳epochMilli转Timestampstatic TimestamptoTimestamp(Instant instant) Instant转Timestampstatic TimestamptoTimestamp(LocalDateTime localDateTime) LocalDateTime转Timestampstatic TimestamptoTimestamp(Date date) Date转Timestampstatic DateTimetoTimeZone(Date date, ZoneId zoneId) Date转换时区static DateTimetoTimeZone(Date date, TimeZone timeZone) Date转换时区static YearMonthtoYearMonth(Instant instant) Instant转YearMonthstatic YearMonthtoYearMonth(LocalDate localDate) LocalDate转YearMonthstatic YearMonthtoYearMonth(LocalDateTime localDateTime) LocalDateTime转YearMonthstatic YearMonthtoYearMonth(ZonedDateTime zonedDateTime) ZonedDateTime转YearMonthstatic YearMonthtoYearMonth(Date date) Date转YearMonthstatic ZonedDateTimetoZonedDateTime(long epochMilli) 时间戳epochMilli毫秒转ZonedDateTime,时区为系统默认时区static ZonedDateTimetoZonedDateTime(Instant instant) Instant转ZonedDateTime,时区为系统默认时区static ZonedDateTimetoZonedDateTime(LocalDate localDate) LocalDate转ZonedDateTime,时区为系统默认时区static ZonedDateTimetoZonedDateTime(LocalDateTime localDateTime) LocalDateTime转ZonedDateTime,时区为系统默认时区static ZonedDateTimetoZonedDateTime(LocalDateTime localDateTime, String zoneId) LocalDateTime转ZonedDateTime,时区为zoneId对应时区 注意,需要保证localDateTime和zoneId是对应的,不然会出现错误static ZonedDateTimetoZonedDateTime(LocalTime localTime) LocalTime转ZonedDateTime 以当天的日期+LocalTime组成新的ZonedDateTime,时区为系统默认时区static ZonedDateTimetoZonedDateTime(TemporalAccessor temporal) temporal转ZonedDateTime,时区为系统默认时区static ZonedDateTimetoZonedDateTime(Date date) Date转ZonedDateTime,时区为系统默认时区static ZonedDateTimetoZonedDateTime(Date date, String zoneId) Date转ZonedDateTimestatic ZonedDateTimetoZonedDateTime(Date date, ZoneId zone) Date转ZonedDateTimeMethods inherited from class org.aoju.bus.core.date.Formatter
format, format, format, format, format, format, format, format, format, format, format, format, format, format, format, format, format, formatBetween, formatBetween, formatBetween, formatBetween, formatDate, formatDate, formatTime, getShotName, newSimpleFormat, newSimpleFormat, parse, parse, parse, parse, parse, parse, parse, parse, parseByPatterns, parseByPatterns, parseByPatterns, parseByPatterns
-
Constructor Details
-
Converter
public Converter()
-
-
Method Details
-
toDate
LocalDateTime转Date- Parameters:
localDateTime- LocalDateTime- Returns:
- Date
-
toDate
-
toDate
-
toDate
-
toDate
时间戳epochMilli毫秒转Date- Parameters:
epochMilli- 时间戳- Returns:
- Date
-
toDate
ZonedDateTime转Date 注意时间对应的时区和默认时区差异- Parameters:
zonedDateTime- ZonedDateTime- Returns:
- Date
-
toDate
-
toDateStartOfMonth
-
toDateEndOfMonth
-
toLocalDateTime
Date转LocalDateTime- Parameters:
date- Date- Returns:
- LocalDateTime
-
toLocalDateTime
Timestamp转LocalDateTime- Parameters:
timestamp- Timestamp- Returns:
- LocalDateTime
-
toLocalDateTime
LocalDate转LocalDateTime- Parameters:
localDate- LocalDate- Returns:
- LocalDateTime
-
toLocalDateTime
LocalTime转LocalDateTime 以当天的日期+LocalTime组成新的LocalDateTime- Parameters:
localTime- LocalTime- Returns:
- LocalDateTime
-
toLocalDateTime
Instant转LocalDateTime- Parameters:
instant- Instant- Returns:
- LocalDateTime
-
toLocalDateTime
时间戳epochMilli毫秒转LocalDateTime- Parameters:
epochMilli- 时间戳- Returns:
- LocalDateTime
-
toLocalDateTime
temporal转LocalDateTime- Parameters:
temporal- TemporalAccessor- Returns:
- LocalDateTime
-
toLocalDateTime
ZonedDateTime转LocalDateTime 注意时间对应的时区和默认时区差异- Parameters:
zonedDateTime- ZonedDateTime- Returns:
- LocalDateTime
-
toLocalDate
-
toLocalDate
LocalDateTime转LocalDate- Parameters:
localDateTime- LocalDateTime- Returns:
- LocalDate
-
toLocalDate
-
toLocalDate
时间戳epochMilli毫秒转LocalDate- Parameters:
epochMilli- 时间戳- Returns:
- LocalDate
-
toLocalDate
temporal转LocalDate- Parameters:
temporal- TemporalAccessor- Returns:
- LocalDate
-
toLocalDate
ZonedDateTime转LocalDate 注意时间对应的时区和默认时区差异- Parameters:
zonedDateTime- ZonedDateTime- Returns:
- LocalDate
-
toLocalDate
-
toTimeZone
-
toTimeZone
-
toLocalDateStartOfMonth
-
toLocalDateEndOfMonth
-
toLocalTime
-
toLocalTime
LocalDateTime转LocalTime- Parameters:
localDateTime- LocalDateTime- Returns:
- LocalTime
-
toLocalTime
-
toLocalTime
temporal转LocalTime- Parameters:
temporal- TemporalAccessor- Returns:
- LocalTime
-
toLocalTime
ZonedDateTime转LocalTime 注意时间对应的时区和默认时区差异- Parameters:
zonedDateTime- ZonedDateTime- Returns:
- LocalTime
-
toInstant
-
toInstant
-
toInstant
LocalDateTime转Instant- Parameters:
localDateTime- LocalDateTime- Returns:
- Instant
-
toInstant
-
toInstant
-
toInstant
-
toInstant
时间戳epochMilli毫秒转Instant- Parameters:
epochMilli- 时间戳- Returns:
- Instant
-
toInstant
ZonedDateTime转Instant 注意,zonedDateTime时区必须和当前系统时区一致,不然会出现问题- Parameters:
zonedDateTime- ZonedDateTime- Returns:
- Instant
-
toInstant
-
toCalendar
转换为Calendar对象- Parameters:
millis- 时间戳- Returns:
- Calendar对象
-
toCalendar
-
toCalendar
转换为Calendar对象- Parameters:
calendar- 日期对象- Returns:
- Calendar对象
-
toCalendar
-
toEpochMilli
Date转时间戳 从1970-01-01T00:00:00Z开始的毫秒值- Parameters:
date- Date- Returns:
- 时间戳
-
toEpochMilli
Timestamp转时间戳 从1970-01-01T00:00:00Z开始的毫秒值- Parameters:
timestamp- Timestamp- Returns:
- 时间戳
-
toEpochMilli
LocalDateTime转时间戳 从1970-01-01T00:00:00Z开始的毫秒值- Parameters:
localDateTime- LocalDateTime- Returns:
- 时间戳
-
toEpochMilli
LocalDate转时间戳 从1970-01-01T00:00:00Z开始的毫秒值- Parameters:
localDate- LocalDate- Returns:
- 时间戳
-
toEpochMilli
Instant转时间戳 从1970-01-01T00:00:00Z开始的毫秒值- Parameters:
instant- Instant- Returns:
- 时间戳
-
toEpochMilli
ZonedDateTime转时间戳,注意,zonedDateTime时区必须和当前系统时区一致,不然会出现问题 从1970-01-01T00:00:00Z开始的毫秒值- Parameters:
zonedDateTime- ZonedDateTime- Returns:
- 时间戳
-
toEpochMilli
- Parameters:
temporalAccessor- Date对象- Returns:
Instant对象
-
toZonedDateTime
Date转ZonedDateTime,时区为系统默认时区- Parameters:
date- Date- Returns:
- ZonedDateTime
-
toZonedDateTime
Date转ZonedDateTime- Parameters:
date- DatezoneId- 目标时区- Returns:
- ZonedDateTime
-
toZonedDateTime
Date转ZonedDateTime- Parameters:
date- Datezone- 目标时区- Returns:
- ZonedDateTime
-
toZonedDateTime
LocalDateTime转ZonedDateTime,时区为系统默认时区- Parameters:
localDateTime- LocalDateTime- Returns:
- ZonedDateTime
-
toZonedDateTime
LocalDateTime转ZonedDateTime,时区为zoneId对应时区 注意,需要保证localDateTime和zoneId是对应的,不然会出现错误- Parameters:
localDateTime- LocalDateTimezoneId- LocalDateTime- Returns:
- ZonedDateTime
-
toZonedDateTime
LocalDate转ZonedDateTime,时区为系统默认时区- Parameters:
localDate- LocalDate- Returns:
- ZonedDateTime such as 2020-02-19T00:00+08:00[Asia/Shanghai]
-
toZonedDateTime
LocalTime转ZonedDateTime 以当天的日期+LocalTime组成新的ZonedDateTime,时区为系统默认时区- Parameters:
localTime- LocalTime- Returns:
- ZonedDateTime
-
toZonedDateTime
Instant转ZonedDateTime,时区为系统默认时区- Parameters:
instant- Instant- Returns:
- ZonedDateTime
-
toZonedDateTime
时间戳epochMilli毫秒转ZonedDateTime,时区为系统默认时区- Parameters:
epochMilli- 时间戳- Returns:
- ZonedDateTime
-
toZonedDateTime
temporal转ZonedDateTime,时区为系统默认时区- Parameters:
temporal- TemporalAccessor- Returns:
- ZonedDateTime
-
toYearMonth
-
toYearMonth
LocalDateTime转YearMonth- Parameters:
localDateTime- LocalDateTime- Returns:
- YearMonth
-
toYearMonth
-
toYearMonth
-
toYearMonth
ZonedDateTime转YearMonth- Parameters:
zonedDateTime- ZonedDateTime- Returns:
- YearMonth
-
toTimestamp
-
toTimestamp
LocalDateTime转Timestamp- Parameters:
localDateTime- LocalDateTime- Returns:
- Timestamp
-
toTimestamp
-
toTimestamp
时间戳epochMilli转Timestamp- Parameters:
epochMilli- 时间戳- Returns:
- Timestamp
-
toTime
秒数转为时间格式(HH:mm:ss)- Parameters:
seconds- 需要转换的秒数- Returns:
- 转换后的字符串
-
toSecond
HH:mm:ss 时间格式字符串转为秒数- Parameters:
time- 字符串时分秒(HH:mm:ss)格式- Returns:
- 时分秒转换后的秒数
-