java.lang.Object
id.luckynetwork.lyrams.lyralibs.core.utils.DateUtils

public class DateUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    durationToLong(int duration, TimeUnit timeUnit)
    Convert a duration to milliseconds.
    long
    It takes a string like "1h" or "2weeks" and converts it to a long value in milliseconds
    durationToString(long duration)
    It converts a duration in milliseconds to a human-readable string.
    This function returns the current date
    void
    This function sets the date format to the format specified by the user.
    void
    setTimeZone(String timeZone)
    Set the time zone for the date format.
    toDate(long millis)
    > It takes a long value representing milliseconds since the epoch, and returns a string representing the date in the format "yyyy-MM-dd"
    static long
    toTicks(long amount, TimeUnit timeUnit)
    Converts the given amount of time in the given unit to ticks.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DateUtils

      public DateUtils()
  • Method Details

    • setDateFormat

      public void setDateFormat(String format)
      This function sets the date format to the format specified by the user.
      Parameters:
      format - The format of the date.
    • setTimeZone

      public void setTimeZone(String timeZone)
      Set the time zone for the date format.
      Parameters:
      timeZone - The time zone to use for the date format.
    • getFormattedDate

      public String getFormattedDate()
      This function returns the current date
      Returns:
      The current date and time
    • toDate

      public String toDate(long millis)
      > It takes a long value representing milliseconds since the epoch, and returns a string representing the date in the format "yyyy-MM-dd"
      Parameters:
      millis - The time in milliseconds to convert to a date.
      Returns:
      A string representation of the date.
    • toTicks

      public static long toTicks(long amount, TimeUnit timeUnit)
      Converts the given amount of time in the given unit to ticks.
      Parameters:
      amount - The amount of time to convert
      timeUnit - The unit of time to convert to ticks.
      Returns:
      The amount of ticks in the given amount of time.
    • durationToLong

      public long durationToLong(int duration, TimeUnit timeUnit)
      Convert a duration to milliseconds.
      Parameters:
      duration - The amount of time to convert
      timeUnit - The time unit of the duration parameter.
      Returns:
      The duration in milliseconds.
    • durationToLong

      public long durationToLong(String duration)
      It takes a string like "1h" or "2weeks" and converts it to a long value in milliseconds
      Parameters:
      duration - The duration string to convert.
      Returns:
      The duration in milliseconds.
    • durationToString

      public String durationToString(long duration)
      It converts a duration in milliseconds to a human-readable string.
      Parameters:
      duration - The duration in milliseconds
      Returns:
      A string that represents the duration in months, days, hours, minutes, and seconds.