public class DateTime extends java.lang.Object implements java.lang.Comparable<DateTime>
Call the setTimezone() method before calculations. You can get the session time zone of the user with the method ConnectionAttributes.getSessionTimeZone()
Constructor and Description |
---|
DateTime(DateTime copy)
Copy constructor.
|
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(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. |
Modifier and Type | Method and 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() |
public DateTime(java.lang.String date)
DateTime
from the specified String
.
The format of the the parameter date
must be one of:
String
can be used to create an empty DateTime
object.
In this case the method isEmpty
will return true
.date
- String containing a date or an empty Stringpublic DateTime(java.lang.String date, java.util.TimeZone tz)
DateTime
from the specified String
and timezone.
The format of the the parameter date
must be one of:
String
can be used to create an empty DateTime
object.
In this case the method isEmpty
will return true
.date
- String containing a date or an empty Stringtz
- Session timezone of the userpublic DateTime(int year, int mon, int day)
DateTime
from the specified integer values.year
- Year with 4 digits for example 2006mon
- Month starting with 1day
- Day in monthpublic DateTime(int year, int mon, int day, int hour, int minutes, int second)
DateTime
from the specified integer values.year
- Year with 4 digits for example 2006mon
- Month starting with 1day
- Day in monthhour
- Hour of the day (24h)minutes
- Minutesecond
- secondpublic DateTime(int year, int mon, int day, int hour, int minutes)
DateTime
from the specified integer values.year
- Year with 4 digits for example 2006mon
- Month starting with 1day
- Day in monthhour
- Hour of the day (24h)minutes
- Minutepublic DateTime(DateTime copy)
copy
parameter.copy
- DateTime instancepublic DateTime copy()
public void setTimezone(java.util.TimeZone timezone)
timezone
- Timezonepublic int getHour()
public int getMinute()
public int getSecond()
public java.lang.String getTime()
String
.
If this is an empty DateTime
object 00:00 is returned.public java.lang.String getDate()
String
.
If this is an empty DateTime
object an empty String
is returned.public static DateTime now()
DateTime
object and sets the date and time to the current date and time.
This method uses the default time zone of the JVM.public static DateTime now(java.util.TimeZone tz)
DateTime
object and sets the date and time to the current date and time.
This method uses the specified time zone.tz
- Time zonepublic static DateTime nowDate()
DateTime
object and sets the date to the current date and sets all time fields to 0.public DateTime addDays(int days)
DateTime
.
Negative parameters are supported.days
- Number of days to addpublic DateTime addYears(int years)
DateTime
.
Negative parameters are supported.years
- Number of years to addpublic DateTime addMinutes(int minutes)
DateTime
.minutes
- Number of minutespublic DateTime addSeconds(int seconds)
DateTime
.seconds
- Number of secondspublic DateTime addMonth(int numberOfMonth)
numberOfMonth
- month countpublic int getWeekday()
public int getWeekOfYear()
public boolean isEmpty()
true
if this is an empty DateTime
object.true
if this DateTime
does
not contain a date valuepublic long getTimeInMillis()
public java.lang.String getTimeWithSeconds()
public int getYear()
DateTime
object.public int getMonth()
DateTime
object.public int getDay()
DateTime
object.public int compareTo(DateTime other)
compareTo
in interface java.lang.Comparable<DateTime>
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object