Class Dates


  • public class Dates
    extends Object
    • Constructor Detail

      • Dates

        public Dates()
    • Method Detail

      • makeDate

        public static Date makeDate​(int year,
                                    int month,
                                    int day)
      • seconds

        public static long seconds​(double num)
      • minutes

        public static long minutes​(double num)
      • hours

        public static long hours​(double num)
      • days

        public static long days​(double num)
      • after

        public static Date after​(Date date,
                                 long timeMs)
      • before

        public static Date before​(Date date,
                                  long timeMs)
      • afterNow

        public static Date afterNow​(long timeMs)
      • beforeNow

        public static Date beforeNow​(long timeMs)
      • makeDate

        public static Date makeDate​(int year,
                                    int month,
                                    int day,
                                    Calendar calendar)
      • now

        public static Date now()
      • today

        public static Date today()
      • tomorrow

        public static Date tomorrow()
      • yesterday

        public static Date yesterday()
        Since:
        6.5
      • after

        public static Date after​(Date date)
      • before

        public static Date before​(Date date)
      • makeDate

        public static Date makeDate​(int year,
                                    int month,
                                    int day,
                                    int hour,
                                    int minute,
                                    int second,
                                    String timeZone)
      • isBeforeWithError

        public static boolean isBeforeWithError​(Date before,
                                                Date after,
                                                long allowedError)
      • daysBeforeNow

        public static Date daysBeforeNow​(int days)
      • daysAfterNow

        public static Date daysAfterNow​(int days)
      • daysBefore

        public static Date daysBefore​(Date date,
                                      int days)
      • daysAfter

        public static Date daysAfter​(Date date,
                                     int days)
      • truncateTime

        public static Date truncateTime​(Date dateAndTime)
      • truncateCalendar

        public static void truncateCalendar​(Calendar calendar)
      • truncateCalendarToEndOfDay

        public static void truncateCalendarToEndOfDay​(Calendar calendar)
      • isDayChanged

        public static boolean isDayChanged​(@NotNull
                                           Date date1,
                                           @NotNull
                                           Date date2)
      • formatDate

        @NotNull
        public static String formatDate​(@NotNull
                                        Date date,
                                        @NotNull
                                        String pattern,
                                        @NotNull
                                        TimeZone tz)
        Formats date according to specified timezone.
        Parameters:
        date - date
        pattern - pattern
        tz - timezone
        Returns:
        formatted date in specified timezone
      • convertDateToFormalString

        public static String convertDateToFormalString​(Date date)
        Converts a date to a formal string like 19991231, independent of current locale.

        Nulls are converted to empty strings.

        Parameters:
        date - date to convert.
        Returns:
        8-digits string in form YYYYMMDD.
      • convertTimeToFormalString

        public static String convertTimeToFormalString​(Date time)
        Converts a timestamp to a formal string like 19991231.235959, independent of current locale.

        Nulls are converted to empty strings.

        Parameters:
        time - timestamp to convert.
        Returns:
        15-character string in form YYYYMMDD.HHMMSS.
      • isSameDay

        public static boolean isSameDay​(@NotNull
                                        Calendar cal1,
                                        @NotNull
                                        Calendar cal2)
        Return true if two dates have the same day of the same year (but may have different time). We use Calendar because timezone issue is very important for the comparison.
        Returns:
        see above
        Since:
        6.0
      • daysBetween

        public static int daysBetween​(@NotNull
                                      Date startDate,
                                      @NotNull
                                      Date endDate)
        Returns number of calendar days between two dates.
        Parameters:
        startDate - start date
        endDate - end date, endDate must be after the startDate
        Returns:
        number of days between specified dates
      • toStandardDate

        @NotNull
        public static Date toStandardDate​(@NotNull
                                          Date date)
        Prevents using inheritors of java.util.Date (e.g. java.sql.Date, java.sql.Time, java.sql.Timestamp). This method should be used when you need to serialize date value (e.g. for XML-RPC).
        Parameters:
        date - original date value
        Returns:
        instance of exactly java.util.Date with the specified date value
      • getSortedTimeZones

        public static TimeZone[] getSortedTimeZones()
      • formatNanos

        @NotNull
        public static String formatNanos​(long nanos)
        Returns string representation of nanoseconds in {seconds}s{millis}ms{micros}us{nanos}ns format. If some component is a zero it is not included.
        Parameters:
        nanos - interval in nanoseconds
        Returns:
        see above
      • formatTimeZoneLong

        public static String formatTimeZoneLong​(@NotNull
                                                TimeZone tz)
      • formatTimeZoneID

        public static String formatTimeZoneID​(@NotNull
                                              TimeZone tz)
      • getTimeZoneDescription

        @NotNull
        public static String getTimeZoneDescription​(@Nullable
                                                    String timeZone)
      • formatTimeZoneUTCOffset

        public static String formatTimeZoneUTCOffset()
      • formatTimeZoneUTCOffset

        public static String formatTimeZoneUTCOffset​(@NotNull
                                                     TimeZone tz)
      • isValidTimeZoneID

        public static boolean isValidTimeZoneID​(@NotNull
                                                String tzID)
      • getSimpleFileDateFormatter

        public static SimpleDateFormat getSimpleFileDateFormatter()