Class DateTime


  • public class DateTime
    extends java.lang.Object
    A helper class for date/time calculations.
    • Field Detail

      • UTC

        public static final java.util.TimeZone UTC
      • ticks

        protected long ticks
      • EMPTY

        public static final DateTime EMPTY
    • Constructor Detail

      • DateTime

        public DateTime()
        Creates a new DateTime representing current date and time (now).
        Parameters:
        date -
      • DateTime

        public DateTime​(long time)
      • DateTime

        public DateTime​(java.sql.Timestamp timestamp)
        Creates a new DateTime object from an existing java.sql.Timestamp object.
        Parameters:
        date -
      • DateTime

        public DateTime​(java.sql.Timestamp timestamp,
                        boolean isLocal)
      • DateTime

        public DateTime​(java.util.Date date,
                        boolean isLocal)
        Creates a new DateTime object from an existing java.util.Date object.
        Parameters:
        date -
      • DateTime

        public DateTime​(java.util.Date date)
      • DateTime

        public DateTime​(java.lang.String str)
        Creates a new DateTime object from a string in "2009-01-01T00:00:00" or "2009-01-01" format.
        Parameters:
        date -
      • DateTime

        public DateTime​(int year,
                        int month,
                        int day)
      • DateTime

        public DateTime​(long ticks,
                        java.util.TimeZone tz)
    • Method Detail

      • calendar

        protected java.util.Calendar calendar()
      • fromDateLocal

        public static DateTime fromDateLocal​(java.util.Date date)
      • toStringSortable

        public java.lang.String toStringSortable()
        Converts DateTime to a sortable string format. Uses toStringIso8601().
        Parameters:
        date -
      • toStringIso8601

        public java.lang.String toStringIso8601()
        Converts DateTime to a String in ISO 8601 format ("2009-01-01T00:00:00").
        Parameters:
        date -
      • toString

        public java.lang.String toString()
        Converts DateTime to a String in "2009-01-01T00:00:00" format.
        Overrides:
        toString in class java.lang.Object
        Parameters:
        date -
      • toString

        public java.lang.String toString​(java.lang.String pattern)
        Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html). Uses the default locale (Locale.getDefault()).
        Parameters:
        pattern -
        Returns:
        Formatted String.
      • toDateString

        public java.lang.String toDateString​(java.util.Locale locale)
      • toDateTimeString

        public java.lang.String toDateTimeString​(java.util.Locale locale)
      • toString

        public java.lang.String toString​(java.lang.String pattern,
                                         java.util.Locale locale)
        Formats the date using the specified pattern (see http://java.sun.com/javase/6/docs/api/index.html?java/text/SimpleDateFormat.html) and locale.
        Parameters:
        pattern -
        locale -
        Returns:
        Formatted String.
      • toTimeStamp

        public java.sql.Timestamp toTimeStamp()
        Converts DateTime to a java.sql.Timestamp object.
        Parameters:
        date -
      • addDays

        public DateTime addDays​(int days)
        Returns a new DateTime object, increased by the specified number of days (accepts negative values).
        Parameters:
        days -
        Returns:
      • addMinutes

        public DateTime addMinutes​(int minutes)
        Returns a new DateTime object, increased by the specified number of minutes (accepts negative values).
        Parameters:
        days -
        Returns:
      • parseAsLocal

        public static DateTime parseAsLocal​(java.lang.Object o)
      • parseString

        public static DateTime parseString​(java.lang.String str)
      • parse

        public static DateTime parse​(java.lang.Object o,
                                     boolean isLocal)
      • toDate

        public java.util.Date toDate()
      • toDateLocal

        public java.util.Date toDateLocal()
      • getYear

        public int getYear()
      • getMonth

        public int getMonth()
      • getDay

        public int getDay()
      • getDatePart

        public DateTime getDatePart()
      • getHour

        public int getHour()
      • getDayOfWeek

        public DayOfWeek getDayOfWeek()
      • getDayOfWeekOrdinal

        public int getDayOfWeekOrdinal()
        Returns:
        Sunday = 0, Monday = 1, etc.
      • toDateString

        public java.lang.String toDateString()
      • getToday

        public static DateTime getToday()
      • today

        public static DateTime today()
      • getDayOfYear

        public int getDayOfYear()
      • getMinute

        public int getMinute()
      • getTimeOfDay

        public TimeSpan getTimeOfDay()
      • getTicks

        public long getTicks()
      • before

        public boolean before​(DateTime another)
      • addHours

        public DateTime addHours​(int hours)
      • addMonths

        public DateTime addMonths​(int months)
      • addYears

        public DateTime addYears​(int years)
      • after

        public boolean after​(DateTime another)
      • equals

        public boolean equals​(java.lang.Object another)
        Overrides:
        equals in class java.lang.Object
      • addSeconds

        public DateTime addSeconds​(int seconds)
      • beforeOrEqual

        public boolean beforeOrEqual​(DateTime another)
      • afterOrEqual

        public boolean afterOrEqual​(DateTime another)
      • canParse

        public static boolean canParse​(java.lang.String text)
        Return true if the string can be parsed using parse().
        Parameters:
        text -
        Returns:
      • isWeekend

        public boolean isWeekend()
      • getMonthName

        public java.lang.String getMonthName​(DateTime date,
                                             java.util.Locale locale)
      • firstDayOfMonth

        public DateTime firstDayOfMonth()
      • getDaysOfMonth

        public int getDaysOfMonth()
      • getDaysOfYear

        public int getDaysOfYear()
      • firstDayOfYear

        public DateTime firstDayOfYear()
      • compareTo

        public int compareTo​(DateTime another)
      • tz

        public DateTime tz​(java.util.TimeZone tz)
        Returns a new DateTime instance with timezone set to tz. TimeZone affects formatting methods (e.g. toString()) and info methods (e.g. getDay()). It doesn't affect the actual time (milliseconds since 1970 UTC).
        Parameters:
        tz -
        Returns:
      • utc

        public DateTime utc()
        Returns a new DateTime instance with timezone set to UTC. TimeZone affects formatting methods (e.g. toString()) and info methods (e.g. getDay()). It doesn't affect the actual time (milliseconds since 1970 UTC).
        Returns:
      • getTimezone

        public java.util.TimeZone getTimezone()
      • setTimezone

        public void setTimezone​(java.util.TimeZone timezone)
      • addMilliSeconds

        public DateTime addMilliSeconds​(int ms)
      • getToday

        public static DateTime getToday​(java.util.TimeZone tz)
        Returns beginning of this day in the given time zone. The timezone of the returned class is set to tz.
        Parameters:
        tz -
        Returns:
      • inZoneByName

        public DateTime inZoneByName​(java.util.TimeZone newZone)