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 Details

  • Method Details

    • 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 of LocalDateTime using 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 of LocalDateTime using 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 instant
      IllegalArgumentException - 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()