Class DateUtils


  • public class DateUtils
    extends java.lang.Object
    Simple Date and time utils.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DateUtils.DefaultCalendarThreadLocal
      Calendar objects are rather expensive: for heavy usage it's a good idea to use a single instance per thread instead of calling Calendar.getInstance() multiple times.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.ThreadLocal<java.util.Calendar> calendarThreadLocal  
    • Constructor Summary

      Constructors 
      Constructor Description
      DateUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long addDays​(long time, int days)  
      static void addDays​(java.util.Calendar calendar, int days)  
      static int getDayAsReadableInt​(long time)
      Readable yyyyMMdd int representation of a day, which is also sortable.
      static int getDayAsReadableInt​(java.util.Calendar calendar)
      Readable yyyyMMdd representation of a day, which is also sortable.
      static int getDayDifference​(long time1, long time2)  
      static int getDayDifferenceOfReadableInts​(int dayOfBroadcast1, int dayOfBroadcast2)  
      static long getTimeForDay​(int year, int month, int day)  
      static long getTimeForDay​(java.util.Calendar calendar, int year, int month, int day)  
      static long getTimeFromDayReadableInt​(int day)
      Returns midnight of the given day.
      static long getTimeFromDayReadableInt​(java.util.Calendar calendar, int readableDay, int hour)  
      static void setTime​(java.util.Calendar calendar, int hourOfDay, int minute, int second, int millisecond)
      Sets hour, minutes, seconds and milliseconds to the given values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • calendarThreadLocal

        private static java.lang.ThreadLocal<java.util.Calendar> calendarThreadLocal
    • Constructor Detail

      • DateUtils

        public DateUtils()
    • Method Detail

      • getTimeForDay

        public static long getTimeForDay​(int year,
                                         int month,
                                         int day)
      • getTimeForDay

        public static long getTimeForDay​(java.util.Calendar calendar,
                                         int year,
                                         int month,
                                         int day)
        Parameters:
        calendar - helper object needed for conversion
      • setTime

        public static void setTime​(java.util.Calendar calendar,
                                   int hourOfDay,
                                   int minute,
                                   int second,
                                   int millisecond)
        Sets hour, minutes, seconds and milliseconds to the given values. Leaves date info untouched.
      • getDayAsReadableInt

        public static int getDayAsReadableInt​(long time)
        Readable yyyyMMdd int representation of a day, which is also sortable.
      • getDayAsReadableInt

        public static int getDayAsReadableInt​(java.util.Calendar calendar)
        Readable yyyyMMdd representation of a day, which is also sortable.
      • getTimeFromDayReadableInt

        public static long getTimeFromDayReadableInt​(int day)
        Returns midnight of the given day.
      • getTimeFromDayReadableInt

        public static long getTimeFromDayReadableInt​(java.util.Calendar calendar,
                                                     int readableDay,
                                                     int hour)
        Parameters:
        calendar - helper object needed for conversion
      • getDayDifferenceOfReadableInts

        public static int getDayDifferenceOfReadableInts​(int dayOfBroadcast1,
                                                         int dayOfBroadcast2)
      • getDayDifference

        public static int getDayDifference​(long time1,
                                           long time2)
      • addDays

        public static long addDays​(long time,
                                   int days)
      • addDays

        public static void addDays​(java.util.Calendar calendar,
                                   int days)