Package com.uc4.api
Class DateTime
java.lang.Object
com.uc4.api.DateTime
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionDateTime(int year, int mon, int day) Constructs a newDateTimefrom the specified integer values.DateTime(int year, int mon, int day, int hour, int minutes) Constructs a newDateTimefrom the specified integer values.DateTime(int year, int mon, int day, int hour, int minutes, int second) Constructs a newDateTimefrom the specified integer values.Copy constructor.Constructs aDateTimefrom the specifiedString.Constructs aDateTimefrom the specifiedStringand timezone. -
Method Summary
Modifier and TypeMethodDescriptionaddDays(int days) Adds the specified number of days to thisDateTime.addMinutes(int minutes) Adds the specified number of minutes to thisDateTime.addMonth(int numberOfMonth) Adds the specified number of month.addSeconds(int seconds) Adds the specified number of seconds to thisDateTime.addYears(int years) Adds the specified number of years to thisDateTime.intcopy()booleangetDate()Returns the date asString.intgetDay()Returns the day of month of thisDateTimeobject.intgetHour()Returns the hour of the day.intReturns the minute.intgetMonth()Returns the month of thisDateTimeobject.intReturns the second.getTime()Returns the time in the format hh:mm asString.longGets this DateTime's value as long.Returns the time including seconds.intintReturns the week number.intgetYear()Returns the 4-digit year of thisDateTimeobject.inthashCode()booleanisEmpty()Returnstrueif this is an emptyDateTimeobject.static DateTimenow()Constructs a newDateTimeobject and sets the date and time to the current date and time.static DateTimeConstructs a newDateTimeobject and sets the date and time to the current date and time.static DateTimenowDate()Constructs a newDateTimeobject and sets the date to the current date and sets all time fields to 0.voidsetTimezone(TimeZone timezone) Sets the timezone for calculations, for example addSeconds().toString()
-
Constructor Details
-
DateTime
Constructs aDateTimefrom the specifiedString.The format of the the parameter
datemust be one of:- YYYY-MM-DD hh:mm:ss
- YYYY-MM-DD
- YYYY-MM-DD hh:mm
Stringcan be used to create an emptyDateTimeobject. In this case the methodisEmptywill returntrue.- Parameters:
date- String containing a date or an empty String
-
DateTime
Constructs aDateTimefrom the specifiedStringand timezone.The format of the the parameter
datemust be one of:- YYYY-MM-DD hh:mm:ss
- YYYY-MM-DD
- YYYY-MM-DD hh:mm
Stringcan be used to create an emptyDateTimeobject. In this case the methodisEmptywill returntrue.- Parameters:
date- String containing a date or an empty Stringtz- Session timezone of the user
-
DateTime
public DateTime(int year, int mon, int day) Constructs a newDateTimefrom the specified integer values.- Parameters:
year- Year with 4 digits for example 2006mon- Month starting with 1day- Day in month
-
DateTime
public DateTime(int year, int mon, int day, int hour, int minutes, int second) Constructs a newDateTimefrom the specified integer values.- Parameters:
year- Year with 4 digits for example 2006mon- Month starting with 1day- Day in monthhour- Hour of the day (24h)minutes- Minutesecond- second
-
DateTime
public DateTime(int year, int mon, int day, int hour, int minutes) Constructs a newDateTimefrom the specified integer values.- Parameters:
year- Year with 4 digits for example 2006mon- Month starting with 1day- Day in monthhour- Hour of the day (24h)minutes- Minute
-
DateTime
Copy constructor. Creates a new instance using the same value as in the specifiedcopyparameter.- Parameters:
copy- DateTime instance
-
-
Method Details
-
copy
- Returns:
- A copy of the current DateTime, including the timezone.
-
setTimezone
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
Returns the time in the format hh:mm asString. If this is an emptyDateTimeobject 00:00 is returned.- Returns:
- String containing the time
-
getDate
Returns the date asString. If this is an emptyDateTimeobject an emptyStringis returned.- Returns:
- String containing the date (Format YYYY-MM-DD) or an empty String
-
now
Constructs a newDateTimeobject 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
Constructs a newDateTimeobject 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
Constructs a newDateTimeobject 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
Adds the specified number of days to thisDateTime. Negative parameters are supported.- Parameters:
days- Number of days to add- Returns:
- This DateTime instance
-
addYears
Adds the specified number of years to thisDateTime. Negative parameters are supported.- Parameters:
years- Number of years to add- Returns:
- This DateTime instance
-
addMinutes
Adds the specified number of minutes to thisDateTime.- Parameters:
minutes- Number of minutes- Returns:
- this instance
-
addSeconds
Adds the specified number of seconds to thisDateTime.- Parameters:
seconds- Number of seconds- Returns:
- this instance
-
addMonth
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()Returnstrueif this is an emptyDateTimeobject.- Returns:
- Boolean which is set to
trueif thisDateTimedoes 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
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 thisDateTimeobject.- Returns:
- Integer containing the year
-
getMonth
public int getMonth()Returns the month of thisDateTimeobject.- Returns:
- Integer containing the month
-
getDay
public int getDay()Returns the day of month of thisDateTimeobject.- Returns:
- Integer containing the day of month
-
compareTo
- Specified by:
compareToin interfaceComparable<DateTime>
-
equals
-
hashCode
public int hashCode() -
toString
-