public final class DateTimeComponents extends Object implements Comparable<DateTimeComponents>, Serializable
Contains the raw components of a date-time value.
Examples:
//July 22, 2013 at 17:25 DateTimeComponents components = new DateTimeComponents(2013, 07, 22, 17, 25, 0, false); //parsing a date string (accepts basic and extended formats) DateTimeComponents components = DateTimeComponents.parse("20130722T172500"); //converting to date string DateTimeComponents components = new DateTimeComponents(2013, 07, 22, 17, 25, 0, false); String str = components.toString(true); //"2013-07-22T17:25:00" //converting to a Date object DateTimeComponents components = new DateTimeComponents(2013, 07, 22, 17, 25, 0, false); Date date = components.toDate();
Constructor and Description |
---|
DateTimeComponents(Date date)
Creates a set of date-time components in the local timezone from a
Date object. |
DateTimeComponents(DateTimeComponents original)
Copies an existing DateTimeComponents object.
|
DateTimeComponents(DateTimeComponents original,
Integer year,
Integer month,
Integer date,
Integer hour,
Integer minute,
Integer second,
Boolean utc)
Copies an existing DateTimeComponents object.
|
DateTimeComponents(Date date,
TimeZone timezone)
Creates a set of date-time components from a
Date object. |
DateTimeComponents(int year,
int month,
int date)
Creates a set of date components.
|
DateTimeComponents(int year,
int month,
int date,
int hour,
int minute,
int second,
boolean utc)
Creates a set of date-time components.
|
Modifier and Type | Method and Description |
---|---|
boolean |
after(DateTimeComponents that) |
boolean |
before(DateTimeComponents that) |
int |
compareTo(DateTimeComponents that) |
boolean |
equals(Object obj) |
int |
getDate()
Gets the date component
|
int |
getHour()
Gets the hour component
|
int |
getMinute()
Gets the minute component.
|
int |
getMonth()
Gets the month component.
|
int |
getSecond()
Gets the second component.
|
int |
getYear()
Gets the year component.
|
int |
hashCode() |
boolean |
hasTime()
Gets whether these components contain a time component
|
boolean |
isUtc()
Gets whether the time is in UTC or not
|
static DateTimeComponents |
parse(String dateString)
Parses the components out of a date-time string.
|
static DateTimeComponents |
parse(String dateString,
Boolean hasTime)
Parses the components out of a date-time string.
|
Date |
toDate()
Converts the date-time components to a
Date object. |
Date |
toDate(TimeZone timezone)
Converts the date-time components to a
Date object. |
String |
toString()
Converts the date-time components to a string using "basic" format.
|
String |
toString(boolean includeTime,
boolean extended)
Converts the date-time components to a string.
|
public DateTimeComponents(DateTimeComponents original)
original
- the object to copy frompublic DateTimeComponents(DateTimeComponents original, Integer year, Integer month, Integer date, Integer hour, Integer minute, Integer second, Boolean utc)
original
- the object to copy fromyear
- the new year value or null not to changemonth
- the new month value or null not to changedate
- the new date value or null not to changehour
- the new hour value or null not to changeminute
- the new minute value or null not to changesecond
- the new second value or null not to changeutc
- true if the time is in UTC, false if not, or null not to
changepublic DateTimeComponents(int year, int month, int date)
year
- the year (e.g. "2013")month
- the month (e.g. "1" for January)date
- the date of the month (e.g. "15")public DateTimeComponents(int year, int month, int date, int hour, int minute, int second, boolean utc)
year
- the year (e.g. "2013")month
- the month (e.g. "1" for January)date
- the date of the month (e.g. "15")hour
- the hour (e.g. "13")minute
- the minutesecond
- the secondutc
- true if the time is in UTC, false if notpublic DateTimeComponents(Date date)
Date
object.date
- the date objectpublic DateTimeComponents(Date date, TimeZone timezone)
Date
object.date
- the date objecttimezone
- the timezone the date-time components will be inpublic static DateTimeComponents parse(String dateString)
dateString
- the date-time string (basic and extended formats are
supported, e.g. "20130331T020000" or "2013-03-31T02:00:00")IllegalArgumentException
- if the date string cannot be parsedpublic static DateTimeComponents parse(String dateString, Boolean hasTime)
dateString
- the date-time string (basic and extended formats are
supported, e.g. "20130331T020000" or "2013-03-31T02:00:00")hasTime
- true to force the value to be parsed as a date-time value,
false to force the value to be parsed as a date value, null to parse the
value however it isIllegalArgumentException
- if the date string cannot be parsedpublic int getYear()
public int getMonth()
public int getDate()
public boolean hasTime()
public int getHour()
public int getMinute()
public int getSecond()
public boolean isUtc()
public String toString()
public String toString(boolean includeTime, boolean extended)
includeTime
- true to include the time portion, false not toextended
- true to use extended format, false to use basicpublic Date toDate()
Date
object.public Date toDate(TimeZone timezone)
Date
object.public int compareTo(DateTimeComponents that)
compareTo
in interface Comparable<DateTimeComponents>
public boolean before(DateTimeComponents that)
public boolean after(DateTimeComponents that)
Copyright © 2013-2015 Michael Angstadt. All Rights Reserved.