Package org.bardframework.commons.utils
Class DateTimeUtils
- java.lang.Object
-
- org.bardframework.commons.utils.DateTimeUtils
-
public final class DateTimeUtils extends Object
Created by Vahid Zafari on 8/12/2016.
-
-
Field Summary
Fields Modifier and Type Field Description static longYEAR_DURATION_MILLS
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static LocalDateTimedateTimeFromEpochMills(long dateTimeAsMills)Obtains an instance ofLocalDateTimeusing milliseconds from the epoch of 1970-01-01T00:00:00Z.static LocalDatefromEpochMills(long dateAsMills)static LocalDateTimefromEpochMills(long dateTimeAsMills, ZoneId zone)Obtains an instance ofLocalDateTimeusing milliseconds from the epoch of 1970-01-01T00:00:00Z.static longgetNowUtcMills()static ChronoUnittoChronoUnit(TimeUnit unit)static longtoEpochMills(LocalDate date)calculate milliseconds past from the epoch of 1970-01-01T00:00:00Z.static longtoEpochMills(LocalDateTime dateTime)calculatee milliseconds past from the epoch of 1970-01-01T00:00:00Z.static longtoEpochMills(OffsetDateTime dateTime)static StringtoLocalString(LocalDate date)convert date to string divided by '/'static StringtoLocalString(LocalDateTime dateTime)convert date to string divided by '/'static TimeUnittoTimeUnit(ChronoUnit unit)
-
-
-
Field Detail
-
YEAR_DURATION_MILLS
public static final long YEAR_DURATION_MILLS
- See Also:
- Constant Field Values
-
-
Method Detail
-
toEpochMills
public static long toEpochMills(LocalDate date)
calculate milliseconds past from the epoch of 1970-01-01T00:00:00Z.- Parameters:
date- an instance of (@code LocalDate)- Returns:
- past milliseconds from 1970-01-01T00:00:00Z according (!@code date) at 23:59:59:99:999.
- Throws:
IllegalArgumentException- if null date passed to method.
-
fromEpochMills
public static LocalDate fromEpochMills(long dateAsMills)
-
dateTimeFromEpochMills
public static LocalDateTime dateTimeFromEpochMills(long dateTimeAsMills)
Obtains an instance ofLocalDateTimeusing milliseconds from the epoch of 1970-01-01T00:00:00Z. The seconds and nanoseconds are extracted from the specified milliseconds.- Parameters:
dateTimeAsMills- the number of milliseconds after 1970-01-01T00:00:00Z- Returns:
- a LocalDateTime, not null
- Throws:
DateTimeException- if the instant exceeds the maximum or minimum instant
-
fromEpochMills
public static LocalDateTime fromEpochMills(long dateTimeAsMills, ZoneId zone)
Obtains an instance ofLocalDateTimeusing milliseconds from the epoch of 1970-01-01T00:00:00Z. The seconds and nanoseconds are extracted from the specified milliseconds.- Parameters:
dateTimeAsMills- the number of milliseconds from 1970-01-01T00:00:00Z.zone- an isntance of (@code ZoneId) specify zone id for calculating LocalDateTime- Returns:
- a LocalDateTime, not null
- Throws:
DateTimeException- if the instant exceeds the maximum or minimum instantIllegalArgumentException- if null zone passed to method.
-
toEpochMills
public static long toEpochMills(LocalDateTime dateTime)
calculatee milliseconds past from the epoch of 1970-01-01T00:00:00Z.- Parameters:
dateTime- an instance of (@code LocalDateTime)- Returns:
- past milliseconds from 1970-01-01T00:00:00Z.
- Throws:
IllegalArgumentException- if null dateTime passed to method.
-
toEpochMills
public static long toEpochMills(OffsetDateTime dateTime)
-
toLocalString
public static String toLocalString(LocalDateTime dateTime)
convert date to string divided by '/'- Parameters:
dateTime- the dateTime- Returns:
- null if date is null, else date with 'yyyy/MM/dd HH:mm' format
-
toLocalString
public static String toLocalString(LocalDate date)
convert date to string divided by '/'- Parameters:
date- the dateTime- Returns:
- null if date is null, else date with 'yyyy/MM/dd' format
-
toTimeUnit
public static TimeUnit toTimeUnit(ChronoUnit unit)
-
toChronoUnit
public static ChronoUnit toChronoUnit(TimeUnit unit)
-
getNowUtcMills
public static long getNowUtcMills()
-
-