Package com.ethlo.time
Class DateTime
java.lang.Object
com.ethlo.time.DateTime
- All Implemented Interfaces:
TemporalAccessor
Container class for parsed date/date-time data. The
getMostGranularField() contains the highest granularity field found, like MONTH, MINUTE, SECOND.-
Constructor Summary
ConstructorsConstructorDescriptionDateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits) -
Method Summary
Modifier and TypeMethodDescriptionbooleanintintReturn the number of significant fraction digits in the second.intgetHour()longgetLong(TemporalField temporalField) intintgetMonth()Returns the most granular field found during parsingintgetNano()Returns the time offset, if availableintintgetYear()inthashCode()booleanincludesGranularity(Field field) Returns if the specified field is part of this date/date-timebooleanisSupported(TemporalField field) static DateTimeof(int year, int month, int day, int hour, int minute, int second, int nanos, TimezoneOffset offset, int fractionDigits) Create a new instance with nanosecond granularity from the input parametersstatic DateTimeof(int year, int month, int day, int hour, int minute, int second, TimezoneOffset offset) Create a new instance with second granularity from the input parametersstatic DateTimeof(int year, int month, int day, int hour, int minute, TimezoneOffset offset) Create a new instance with minute granularity from the input parametersstatic DateTimeof(OffsetDateTime dateTime) Create a new instance with data from the specified date-time.static DateTimeofDate(int year, int month, int day) Create a new instance with day granularity from the input parametersstatic DateTimeofYear(int year) Create a new instance with year granularity from the input parametersstatic DateTimeofYearMonth(int year, int month) Create a new instance with year-month granularity from the input parametersThis method will attempt to create an Instant from whatever granularity is available in the parsed year/date/date-time.Creates aLocalDate, discarding any higher granularity fieldsCreates aLocalDateTimediscarding any timezone informationCreates anOffsetDateTimetoString()Formats this date-time as a date/date-time with the same fields as was parsedtoString(int fractionDigits) Formats this date-time as an RFC-3339 compatible string with the specified number of fractions in the second.Formats this date-time as an ISO formatted string with the last included field as specified.toYear()Creates aYeardiscarding any higher granularity fieldsCreates aYearMonthdiscarding any higher granularity fieldsMethods inherited from interface java.time.temporal.TemporalAccessor
get, query, range
-
Constructor Details
-
DateTime
public DateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits)
-
-
Method Details
-
of
public static DateTime of(int year, int month, int day, int hour, int minute, int second, TimezoneOffset offset) Create a new instance with second granularity from the input parameters- Parameters:
year- yearmonth- monthday- dayhour- hourminute- minutesecond- secondoffset- timezone offset- Returns:
- A DateTime with second granularity
-
of
public static DateTime of(int year, int month, int day, int hour, int minute, int second, int nanos, TimezoneOffset offset, int fractionDigits) Create a new instance with nanosecond granularity from the input parameters- Parameters:
year- yearmonth- monthday- dayhour- hourminute- minutesecond- secondnanos- nanosoffset- timezone offsetfractionDigits- The granularity of the fractional seconds field- Returns:
- A DateTime with nanosecond granularity
-
ofYear
Create a new instance with year granularity from the input parameters- Parameters:
year- The year- Returns:
- a new instance with year granularity from the input parameters
-
ofYearMonth
Create a new instance with year-month granularity from the input parameters- Parameters:
year- The yearmonth- The month- Returns:
- a new instance with year-month granularity from the input parameters
-
ofDate
Create a new instance with day granularity from the input parameters- Parameters:
year- The yearmonth- The monthday- The day- Returns:
- a new instance with day granularity from the input parameters
-
of
public static DateTime of(int year, int month, int day, int hour, int minute, TimezoneOffset offset) Create a new instance with minute granularity from the input parameters- Parameters:
year- The yearmonth- The monthday- The dayhour- The hourminute- The minuteoffset- The timezone offset- Returns:
- a new instance with minute granularity from the input parameters
-
of
Create a new instance with data from the specified date-time.- Parameters:
dateTime- The date-time to copy data from- Returns:
- A new instance
-
includesGranularity
Returns if the specified field is part of this date/date-time- Parameters:
field- The field to check for- Returns:
- True if included, otherwise false
-
getYear
public int getYear() -
getMonth
public int getMonth() -
getDayOfMonth
public int getDayOfMonth() -
getHour
public int getHour() -
getMinute
public int getMinute() -
getSecond
public int getSecond() -
getNano
public int getNano() -
getOffset
Returns the time offset, if available- Returns:
- the time offset, if available
-
toYear
Creates aYeardiscarding any higher granularity fields- Returns:
- the
Year
-
toYearMonth
Creates aYearMonthdiscarding any higher granularity fields- Returns:
- the
YearMonth
-
toLocalDatetime
Creates aLocalDateTimediscarding any timezone information- Returns:
- the
LocalDateTime
-
toOffsetDatetime
Creates anOffsetDateTime- Returns:
- the
OffsetDateTime
-
toLocalDate
Creates aLocalDate, discarding any higher granularity fields- Returns:
- the
LocalDate
-
getMostGranularField
Returns the most granular field found during parsing- Returns:
- The field found
-
toString
Formats this date-time as an ISO formatted string with the last included field as specified.- Parameters:
lastIncluded- The last specified field to include- Returns:
- The formatted date/date-time string
-
toString
Formats this date-time as an RFC-3339 compatible string with the specified number of fractions in the second.- Parameters:
fractionDigits- The number of fractions to include- Returns:
- The formatted date/date-time string
-
getFractionDigits
public int getFractionDigits()Return the number of significant fraction digits in the second.- Returns:
- The number of significant fraction digits
-
toString
Formats this date-time as a date/date-time with the same fields as was parsed -
equals
-
hashCode
public int hashCode() -
isSupported
- Specified by:
isSupportedin interfaceTemporalAccessor
-
getLong
- Specified by:
getLongin interfaceTemporalAccessor
-
toInstant
This method will attempt to create an Instant from whatever granularity is available in the parsed year/date/date-time.
Missing fields will be replaced by their lowest allowed value: 1 for month and day, 0 for any missing time component.
NOTE: If there is no time-zone defined, UTC will be assumed
- Returns:
- An instant representing the point in time.
-