Package com.ethlo.time
Class DateTime
- java.lang.Object
-
- com.ethlo.time.DateTime
-
public class DateTime extends Object
Container class for parsed date/date-time data. ThegetMostGranularField()contains the highest granularity field found, like MONTH, MINUTE, SECOND.
-
-
Constructor Summary
Constructors Constructor Description DateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)* @hiddenintgetDayOfMonth()intgetFractionDigits()Return the number of significant fraction digits in the second.intgetHour()intgetMinute()intgetMonth()FieldgetMostGranularField()Returns the most granular field found during parsingintgetNano()Optional<TimezoneOffset>getOffset()Returns the time offset, if availableintgetSecond()intgetYear()booleanincludesGranularity(Field field)Returns if the specified field is part of this date/date-timestatic 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 years, int months, int days, int hours, 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 years, int months, int days)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 years, int months)Create a new instance with year-month granularity from the input parametersLocalDatetoLocalDate()Creates aLocalDate, discarding any higher granularity fieldsLocalDateTimetoLocalDatetime()Creates aLocalDateTimediscarding any timezone informationOffsetDateTimetoOffsetDatetime()Creates anOffsetDateTimeStringtoString()Formats this date-time as a date/date-time with the same fields as was parsedStringtoString(int fractionDigits)Formats this date-time as an RFC-3339 compatible string with the specified number of fractions in the second.StringtoString(Field lastIncluded)Formats this date-time as an ISO formatted string with the last included field as specified.YeartoYear()Creates aYeardiscarding any higher granularity fieldsYearMonthtoYearMonth()Creates aYearMonthdiscarding any higher granularity fields
-
-
-
Constructor Detail
-
DateTime
public DateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits)
-
-
Method Detail
-
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
-
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
-
ofYear
public static DateTime ofYear(int year)
Create a new instance with year granularity from the input parameters
-
ofYearMonth
public static DateTime ofYearMonth(int years, int months)
Create a new instance with year-month granularity from the input parameters
-
ofDate
public static DateTime ofDate(int years, int months, int days)
Create a new instance with day granularity from the input parameters
-
of
public static DateTime of(int years, int months, int days, int hours, int minute, TimezoneOffset offset)
Create a new instance with minute granularity from the input parameters
-
of
public static DateTime of(OffsetDateTime dateTime)
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
public boolean includesGranularity(Field field)
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
public Optional<TimezoneOffset> getOffset()
Returns the time offset, if available- Returns:
- the time offset, if available
-
toYear
public Year toYear()
Creates aYeardiscarding any higher granularity fields- Returns:
- the
Year
-
toYearMonth
public YearMonth toYearMonth()
Creates aYearMonthdiscarding any higher granularity fields- Returns:
- the
YearMonth
-
toLocalDatetime
public LocalDateTime toLocalDatetime()
Creates aLocalDateTimediscarding any timezone information- Returns:
- the
LocalDateTime
-
toOffsetDatetime
public OffsetDateTime toOffsetDatetime()
Creates anOffsetDateTime- Returns:
- the
OffsetDateTime
-
toLocalDate
public LocalDate toLocalDate()
Creates aLocalDate, discarding any higher granularity fields- Returns:
- the
LocalDate
-
getMostGranularField
public Field getMostGranularField()
Returns the most granular field found during parsing- Returns:
- The field found
-
toString
public String toString(Field lastIncluded)
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
public String toString(int fractionDigits)
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
public String toString()
Formats this date-time as a date/date-time with the same fields as was parsed
-
-