Class DateTimeUtil

java.lang.Object
com.itextpdf.commons.utils.DateTimeUtil

public final class DateTimeUtil extends Object
This file is a helper class for internal usage only. Be aware that its API and functionality may be changed in future.
  • Method Details

    • getUtcMillisFromEpoch

      public static double getUtcMillisFromEpoch (Calendar calendar)
      Gets the Calendar as UTC milliseconds from the epoch.
      Parameters:
      calendar - the calendar to be converted to millis
      Returns:
      the date as UTC milliseconds from the epoch
    • getCalendar

      public static Calendar getCalendar (Date date)
      Gets the date as Calendar.
      Parameters:
      date - the date to be returned as Calendar
      Returns:
      the date as Calendar
    • getCurrentTimeCalendar

      public static Calendar getCurrentTimeCalendar()
      Gets a default GregorianCalendar.
      Returns:
      a default GregorianCalendar using the current time in the default time zone with the default locale
    • getCurrentTimeDate

      public static Date getCurrentTimeDate()
      Gets current time consistently.
      Returns:
      the time at which it was allocated, measured to the nearest millisecond
    • addDaysToCalendar

      public static Calendar addDaysToCalendar (Calendar calendar, int days)
      Adds the specified amount of days to the given calendar field.
      Parameters:
      calendar - the calendar field where to add
      days - the amount of days to be added
      Returns:
      the time at which it was allocated, measured to the nearest millisecond
    • isInPast

      public static boolean isInPast (Date date)
      Defines if date is in past.
      Parameters:
      date - the date to be compared with current date
      Returns:
      true if given date is in past, false instead
    • getRelativeTime

      public static long getRelativeTime (Date date)
      Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.
      Parameters:
      date - the specified date to get time
      Returns:
      the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the specified date
    • addDaysToDate

      public static Date addDaysToDate (Date date, int days)
      Adds the specified amount of days to the given date.
      Parameters:
      date - the specified date to add
      days - the amount of days to be added
      Returns:
      a Date object representing the calendar's time value (millisecond offset from the Epoch)
    • parseWithDefaultPattern

      public static Date parseWithDefaultPattern (String date)
      Parses passing date with default yyyy-MM-dd pattern.
      Parameters:
      date - is date to be parse
      Returns:
      parse date
    • parse

      public static Date parse (String date, String format)
      Parses passing date with specified format.
      Parameters:
      date - the date to be parsed
      format - the format of parsing the date
      Returns:
      parsed date
    • formatWithDefaultPattern

      public static String formatWithDefaultPattern (Date date)
      Format passing date with default yyyy-MM-dd pattern.
      Parameters:
      date - the date to be formatted
      Returns:
      formatted date
    • format

      public static String format (Date date, String pattern)
      Format passing date with specified pattern.
      Parameters:
      date - date to be formatted
      pattern - pattern for format
      Returns:
      formatted date
    • getCurrentTimeZoneOffset

      @Deprecated public static long getCurrentTimeZoneOffset()
      Deprecated.
      Unused and will be removed in the next major release. Use getCurrentTimeZoneOffset(Date) instead.
      Gets the offset of time zone from UTC
      Returns:
      the offset of time zone from UTC
    • getCurrentTimeZoneOffset

      public static long getCurrentTimeZoneOffset (Date date)
      Gets the offset of time zone from UTC at the specified date.
      Parameters:
      date - the date represented in milliseconds since January 1, 1970 00:00:00 GMT
      Returns:
      the offset of time zone from UTC at the specified date adjusted with the amount of daylight saving.