Package com.uc4.api

Class DateTime

  • All Implemented Interfaces:
    java.lang.Comparable<DateTime>

    public class DateTime
    extends java.lang.Object
    implements java.lang.Comparable<DateTime>
    This class represents a local date and time.

    Call the setTimezone() method before calculations. You can get the session time zone of the user with the method ConnectionAttributes.getSessionTimeZone()

    • Constructor Summary

      Constructors 
      Constructor Description
      DateTime​(int year, int mon, int day)
      Constructs a new DateTime from the specified integer values.
      DateTime​(int year, int mon, int day, int hour, int minutes)
      Constructs a new DateTime from the specified integer values.
      DateTime​(int year, int mon, int day, int hour, int minutes, int second)
      Constructs a new DateTime from the specified integer values.
      DateTime​(DateTime copy)
      Copy constructor.
      DateTime​(java.lang.String date)
      Constructs a DateTime from the specified String.
      DateTime​(java.lang.String date, java.util.TimeZone tz)
      Constructs a DateTime from the specified String and timezone.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DateTime addDays​(int days)
      Adds the specified number of days to this DateTime.
      DateTime addMinutes​(int minutes)
      Adds the specified number of minutes to this DateTime.
      DateTime addMonth​(int numberOfMonth)
      Adds the specified number of month.
      DateTime addSeconds​(int seconds)
      Adds the specified number of seconds to this DateTime.
      DateTime addYears​(int years)
      Adds the specified number of years to this DateTime.
      int compareTo​(DateTime other)  
      DateTime copy()  
      boolean equals​(java.lang.Object obj)  
      java.lang.String getDate()
      Returns the date as String.
      int getDay()
      Returns the day of month of this DateTime object.
      int getHour()
      Returns the hour of the day.
      int getMinute()
      Returns the minute.
      int getMonth()
      Returns the month of this DateTime object.
      int getSecond()
      Returns the second.
      java.lang.String getTime()
      Returns the time in the format hh:mm as String.
      long getTimeInMillis()
      Gets this DateTime's value as long.
      java.lang.String getTimeWithSeconds()
      Returns the time including seconds.
      int getWeekday()  
      int getWeekOfYear()
      Returns the week number.
      int getYear()
      Returns the 4-digit year of this DateTime object.
      int hashCode()  
      boolean isEmpty()
      Returns true if this is an empty DateTime object.
      static DateTime now()
      Constructs a new DateTime object and sets the date and time to the current date and time.
      static DateTime now​(java.util.TimeZone tz)
      Constructs a new DateTime object and sets the date and time to the current date and time.
      static DateTime nowDate()
      Constructs a new DateTime object and sets the date to the current date and sets all time fields to 0.
      void setTimezone​(java.util.TimeZone timezone)
      Sets the timezone for calculations, for example addSeconds().
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DateTime

        public DateTime​(java.lang.String date)
        Constructs a DateTime from the specified String.

        The format of the the parameter date must be one of:

        • YYYY-MM-DD hh:mm:ss
        • YYYY-MM-DD
        • YYYY-MM-DD hh:mm
        An empty String can be used to create an empty DateTime object. In this case the method isEmpty will return true.
        Parameters:
        date - String containing a date or an empty String
      • DateTime

        public DateTime​(java.lang.String date,
                        java.util.TimeZone tz)
        Constructs a DateTime from the specified String and timezone.

        The format of the the parameter date must be one of:

        • YYYY-MM-DD hh:mm:ss
        • YYYY-MM-DD
        • YYYY-MM-DD hh:mm
        An empty String can be used to create an empty DateTime object. In this case the method isEmpty will return true.
        Parameters:
        date - String containing a date or an empty String
        tz - Session timezone of the user
      • DateTime

        public DateTime​(int year,
                        int mon,
                        int day)
        Constructs a new DateTime from the specified integer values.
        Parameters:
        year - Year with 4 digits for example 2006
        mon - Month starting with 1
        day - Day in month
      • DateTime

        public DateTime​(int year,
                        int mon,
                        int day,
                        int hour,
                        int minutes,
                        int second)
        Constructs a new DateTime from the specified integer values.
        Parameters:
        year - Year with 4 digits for example 2006
        mon - Month starting with 1
        day - Day in month
        hour - Hour of the day (24h)
        minutes - Minute
        second - second
      • DateTime

        public DateTime​(int year,
                        int mon,
                        int day,
                        int hour,
                        int minutes)
        Constructs a new DateTime from the specified integer values.
        Parameters:
        year - Year with 4 digits for example 2006
        mon - Month starting with 1
        day - Day in month
        hour - Hour of the day (24h)
        minutes - Minute
      • DateTime

        public DateTime​(DateTime copy)
        Copy constructor. Creates a new instance using the same value as in the specified copy parameter.
        Parameters:
        copy - DateTime instance
    • Method Detail

      • copy

        public DateTime copy()
        Returns:
        A copy of the current DateTime, including the timezone.
      • setTimezone

        public void setTimezone​(java.util.TimeZone timezone)
        Sets the timezone for calculations, for example addSeconds(). It is also used for the method: getTimeInMillis() If this method is not called the default timezone is used.
        Parameters:
        timezone - Timezone
      • getHour

        public int getHour()
        Returns the hour of the day.
        Returns:
        Hour of the day
      • getMinute

        public int getMinute()
        Returns the minute.
        Returns:
        Minute
      • getSecond

        public int getSecond()
        Returns the second.
        Returns:
        Second
      • getTime

        public java.lang.String getTime()
        Returns the time in the format hh:mm as String. If this is an empty DateTime object 00:00 is returned.
        Returns:
        String containing the time
      • getDate

        public java.lang.String getDate()
        Returns the date as String. If this is an empty DateTime object an empty String is returned.
        Returns:
        String containing the date (Format YYYY-MM-DD) or an empty String
      • now

        public static DateTime now()
        Constructs a new DateTime object and sets the date and time to the current date and time. This method uses the default time zone of the JVM.
        Returns:
        DateTime filled with current date and time values
      • now

        public static DateTime now​(java.util.TimeZone tz)
        Constructs a new DateTime object and sets the date and time to the current date and time. This method uses the specified time zone.
        Parameters:
        tz - Time zone
        Returns:
        DateTime filled with current date and time values
      • nowDate

        public static DateTime nowDate()
        Constructs a new DateTime object and sets the date to the current date and sets all time fields to 0.
        Returns:
        DateTime filled with current date and time values
      • addDays

        public DateTime addDays​(int days)
        Adds the specified number of days to this DateTime. Negative parameters are supported.
        Parameters:
        days - Number of days to add
        Returns:
        This DateTime instance
      • addYears

        public DateTime addYears​(int years)
        Adds the specified number of years to this DateTime. Negative parameters are supported.
        Parameters:
        years - Number of years to add
        Returns:
        This DateTime instance
      • addMinutes

        public DateTime addMinutes​(int minutes)
        Adds the specified number of minutes to this DateTime.
        Parameters:
        minutes - Number of minutes
        Returns:
        this instance
      • addSeconds

        public DateTime addSeconds​(int seconds)
        Adds the specified number of seconds to this DateTime.
        Parameters:
        seconds - Number of seconds
        Returns:
        this instance
      • addMonth

        public DateTime addMonth​(int numberOfMonth)
        Adds the specified number of month.
        Parameters:
        numberOfMonth - month count
        Returns:
        this instance
      • getWeekday

        public int getWeekday()
        Returns:
        Day of week:
        • 1 ... Sunday
        • 2 ... Monday
        • 3 ... Tuesday
        • 4 ... Wednesday
        • 5 ... Thursday
        • 6 ... Friday
        • 7 ... Saturday
      • getWeekOfYear

        public int getWeekOfYear()
        Returns the week number.
        Returns:
        week number within the current year
      • isEmpty

        public boolean isEmpty()
        Returns true if this is an empty DateTime object.
        Returns:
        Boolean which is set to true if this DateTime does not contain a date value
      • getTimeInMillis

        public long getTimeInMillis()
        Gets this DateTime's value as long.
        Returns:
        The time as UTC milliseconds from the epoch
      • getTimeWithSeconds

        public java.lang.String getTimeWithSeconds()
        Returns the time including seconds. The returned format is hh:mm:ss.
        Returns:
        String containing the time with seconds
      • getYear

        public int getYear()
        Returns the 4-digit year of this DateTime object.
        Returns:
        Integer containing the year
      • getMonth

        public int getMonth()
        Returns the month of this DateTime object.
        Returns:
        Integer containing the month
      • getDay

        public int getDay()
        Returns the day of month of this DateTime object.
        Returns:
        Integer containing the day of month
      • compareTo

        public int compareTo​(DateTime other)
        Specified by:
        compareTo in interface java.lang.Comparable<DateTime>
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object