public final class DateUtils extends Object
Date
) to the new (java.time
) JDK
Special thanks to http://stackoverflow.com/questions/21242110/convert-java-util-date-to-java-time-localdate#answer-27378709
which inspired this code
See also http://stackoverflow.com/questions/19431234/converting-between-java-time-localdatetime-and-java-util-dateModifier | Constructor and Description |
---|---|
private |
DateUtils() |
Modifier and Type | Method and Description |
---|---|
static Date |
asDate(LocalDate localDate)
|
static Date |
asDate(LocalDateTime localDateTime)
Converts this
LocalDateTime object to a Date . |
static Date |
asDate(LocalDateTime localDateTime,
ZoneId zone)
Converts this
LocalDateTime object to a Date . |
static Date |
asDate(LocalDate localDate,
ZoneId zone)
|
static Instant |
asInstant(Date date)
|
static LocalDate |
asLocalDate(Date date)
|
static LocalDate |
asLocalDate(Date date,
ZoneId zone)
|
static LocalDateTime |
asLocalDateTime(Date date)
Converts this
Date object to a LocalDateTime . |
static LocalDateTime |
asLocalDateTime(Date date,
ZoneId zone)
Converts this
Date object to a LocalDateTime . |
static ZonedDateTime |
asZonedDateTime(Date date,
ZoneId zone)
|
static String |
formatDuration(Duration duration)
Format a duration for logs
|
static String |
formatDuration(long duration)
Format a duration for logs
|
private static String |
formatNumber(long number,
int nbNumbers) |
private DateUtils()
public static Instant asInstant(Date date)
date
- The date objectDate
objectpublic static ZonedDateTime asZonedDateTime(Date date, ZoneId zone)
date
- The date objectzone
- The zoneDate
objectpublic static LocalDate asLocalDate(Date date, ZoneId zone)
public static LocalDate asLocalDate(Date date)
public static LocalDateTime asLocalDateTime(Date date, ZoneId zone)
Date
object to a LocalDateTime
.
This returns a LocalDateTime
with the same year, month, day and time as this Date
.date
- The date objectzone
- The zoneLocalDateTime
part of this Date
public static LocalDateTime asLocalDateTime(Date date)
Date
object to a LocalDateTime
.
This returns a LocalDateTime
with the same year, month, day and time as this Date
.date
- The date objectLocalDateTime
part of this Date
public static Date asDate(LocalDateTime localDateTime)
LocalDateTime
object to a Date
.localDateTime
- The local date time objectDate
part of this LocalDateTime
public static Date asDate(LocalDateTime localDateTime, ZoneId zone)
LocalDateTime
object to a Date
.localDateTime
- The local date time objectzone
- The zoneDate
part of this LocalDateTime
public static String formatDuration(Duration duration)
duration
- duration to logpublic static String formatDuration(long duration)
duration
- miliseconds representing the durationprivate static String formatNumber(long number, int nbNumbers)