public class DateTime
extends java.lang.Object
Month.| Modifier and Type | Class and Description |
|---|---|
static class |
DateTime.Unit
Units to be used in
DateTime-mathemathics. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_DATE_TIME_FORMAT
A date-format-pattern to be used for formatting, if no other is defined.
|
| Modifier and Type | Method and Description |
|---|---|
DateTime |
add(long amountToAdd,
DateTime.Unit unit)
Changes a current value of an object for
amountToAdd units of unit |
int |
compareTo(Date other)
Compares an object with another
Date object. |
int |
compareTo(DateTime other)
Compares an object with another
DateTime-object. |
boolean |
equals(java.lang.Object other)
Compares an object to another
DateTime object. |
int |
getDay() |
int |
getHour() |
int |
getMillisecond() |
int |
getMinute() |
int |
getMonth()
Month is INTENTIONALLY returned as an int, in order to avoid dependency on
Month |
int |
getNano() |
int |
getSecond() |
int |
getYear() |
int |
hashCode()
Hashcode of an object.
Hashcode of an object will be a hashcode of its value-container object value |
boolean |
isSameDateAs(Date otherDate)
Compares an object to another
Date-object. |
static DateTime |
now()
Creating a datetime from a current date and current time.
|
static DateTime |
of(Date date)
Creating a datetime from a
Date. |
static DateTime |
of(java.util.Date datetime)
Creating a datetime from a
Date. |
static DateTime |
of(DateTime datetime)
Creating a datetime from another
DateTime. |
static DateTime |
of(Date date,
Time time)
|
static DateTime |
of(java.time.LocalDate date)
Creating a datetime from a
LocalDate. |
static DateTime |
of(java.time.LocalDateTime datetime)
Creating a datetime from a
DateTime |
Date |
toDate() |
DateTime |
toEndOfDay() |
DateTime |
toEndOfYear() |
java.lang.String |
toFormattedString(java.time.format.DateTimeFormatter formatter)
Method which formats a date using
formatter. |
java.util.Date |
toJavaUtilDate()
Converts an object to
Date. |
java.time.LocalDateTime |
toLocalDateTime()
Converts an object to
LocalDateTime. |
DateTime |
toStartOfDay() |
DateTime |
toStartOfYear() |
java.lang.String |
toString()
Converts to
String, using DEFAULT_FORMATTER. |
static java.lang.String |
toString(DateTime dateTime,
java.time.format.DateTimeFormatter formatter)
Converts
dateTime to String, using formatter, following all other rules of formatting. |
java.lang.String |
toString(java.time.format.DateTimeFormatter formatter)
Converts to
String, using formatter. |
static java.lang.String |
toString(DateTime dateTime,
java.util.Locale locale)
Converts
dateTime to String, using locale, following all other rules of formatting. |
static java.lang.String |
toString(DateTime dateTime,
java.lang.String formatDescription)
Converts
dateTime to String, using formatDescription, following all other rules of formatting. |
java.lang.String |
toString(java.util.Locale locale)
Converts to
String, using locale. |
java.lang.String |
toString(java.lang.String formatDescription)
Converts to
String, using a DateTimeFormatter defined by formatDescription. |
Time |
toTime() |
public static final java.lang.String DEFAULT_DATE_TIME_FORMAT
public static DateTime of(Date date, Time time)
date - Date part of an object that should be createdtime - Time part of an object that should be createdDateTime objectpublic static DateTime of(Date date)
Date. Time-part will be zeroed.date - Date part of an object that should be createdDateTime objectpublic static DateTime of(java.time.LocalDate date)
LocalDate. Time-part will be zeroed.date - Date part of an object that should be createdDateTime objectpublic static DateTime of(java.util.Date datetime)
Date.datetime - A Date and Time info defined by Date object.DateTime objectpublic static DateTime now()
DateTime objectpublic DateTime toStartOfYear()
DateTime-object.public DateTime toEndOfYear()
DateTime-object.public DateTime toStartOfDay()
public DateTime toEndOfDay()
public int getYear()
DateTime-objectpublic int getMonth()
MonthDate-object.public int getDay()
DateTime-object.public int getHour()
Time-objectpublic int getMinute()
Time-object.public int getSecond()
Time-object.public int getMillisecond()
public int getNano()
Time-object.public int compareTo(Date other)
Date object.
Comparation is made only on an intersected set of attributes for Date and DateTime.other - An other comparing objectpublic DateTime add(long amountToAdd, DateTime.Unit unit)
amountToAdd units of unitamountToAdd - quantity of unit to be added (or subtracted, if amountToAdd is negative} to a current object.unit - Chrono-unit of measureDateTime-object (in order to enable method-chaining)public java.util.Date toJavaUtilDate()
Date.Date value of an object.public java.time.LocalDateTime toLocalDateTime()
LocalDateTime.LocalDateTime value of an object.public java.lang.String toFormattedString(java.time.format.DateTimeFormatter formatter)
formatter. At this point, formatter can not be null.formatter - Non-null DateTimeFormattervalue is not nullFORMATTED_NULL_DATE_TIME, otherwisepublic java.lang.String toString()
String, using DEFAULT_FORMATTER.toString in class java.lang.Objectpublic java.lang.String toString(java.time.format.DateTimeFormatter formatter)
String, using formatter.
If formatter is null, then a standard toString() is used.formatter - A format to be used when formatting a datetimepublic java.lang.String toString(java.util.Locale locale)
String, using locale.
If locale is null, then a standard DEFAULT_LOCALE is used.locale - A locale to be used when formatting a datetimepublic java.lang.String toString(java.lang.String formatDescription)
String, using a DateTimeFormatter defined by formatDescription.formatDescription - A String-definition of a DateTimeFormatter to be used when formatting a datepublic static java.lang.String toString(DateTime dateTime, java.util.Locale locale)
dateTime to String, using locale, following all other rules of formatting.dateTime - A DateTime-object to be convertedlocale - A locale to be used when formatting a dateTime.toString(Locale locale)public static java.lang.String toString(DateTime dateTime, java.lang.String formatDescription)
dateTime to String, using formatDescription, following all other rules of formatting.dateTime - A DateTime-object to be convertedformatDescription - A String-definition of a DateTimeFormatter to be used when formatting a dateTime.toString(String formatDescription)public static java.lang.String toString(DateTime dateTime, java.time.format.DateTimeFormatter formatter)
dateTime to String, using formatter, following all other rules of formatting.dateTime - A DateTime-object to be convertedformatter - A format to be used when formatting a dateTime.toString(DateTimeFormatter formatter)public int hashCode()
valuehashCode in class java.lang.Objectpublic boolean equals(java.lang.Object other)
DateTime object.
Two DateTime objects will be treated equal, if their value-container objects value are equal.equals in class java.lang.Objecttrue, if objects are equal,false, otherwise.public boolean isSameDateAs(Date otherDate)
Date-object.
The method name is INTENTIONALLY chosen NOT TO BE equals in order to prevent a possible mix-up.Date and DateTime will be treated as "of same date" if they are equal on year/month/dayOfMonth levelotherDate - The other objecttrue, if objects are equal on an intersected set of attributesfalse, otherwise.