Package com.norconex.commons.lang.time
Class DateModel
java.lang.Object
com.norconex.commons.lang.time.DateModel
Class abstracting several date and time implementations
(Date, LocalDate, ZonedDateTime, etc.).
The
Default values
When unspecified, the following are the default values:- Time units: zero
- Zone ID: UTC
When resolving a date with the specified time zone, it is set as the new time zone for the same time units. For example, setting PST as the time zone will change the time portion of a UTC date-time from "13:34 UTC" to "13:34 PST").
Modifying a time unit by calling "set" or "with" methods on it does not
change any of the other time units. This includes the time zone. For
instance, setting "America/Vancouver" time zone on a UTC date will result
in the same clock time, but in a different time zone. E.g.,:
2022-11-10T04:49:51.000Z will become
2022-11-10T04:49:51.000-08:00[America/Vancouver]
-
Method Summary
Modifier and TypeMethodDescriptionintday()day(int day) booleaninthashCode()inthour()hour(int hour) intminute()minute(int minute) intmonth()month(int month) intnano()nano(int nano) static DateModelof(int year, int month, int day) static DateModelof(int year, int month, int day, int hour, int minute, int second) static DateModelof(long epoch) static DateModelCreate a date model out of a date string representation, in the format defined by eitherDateTimeFormatter.ISO_DATE_TIMEfor date-time orDateTimeFormatter.ISO_DATEfor date-only.static DateModelof(@NonNull String dateStr, @NonNull ZonedDateTimeParser parser) Create a date model out of a date string representation, based on settings defined in the suppliedZonedDateTimeParser.static DateModelstatic DateModelstatic DateModelof(@NonNull LocalDateTime ldt) static DateModelof(@NonNull ZonedDateTime zdt) static DateModelintsecond()second(int second) booleanstartOfDay(boolean startOfDay) toDate()longtoEpoch()toString()Return the date as a string representation in the format defined byDateTimeFormatter.ISO_DATE_TIME.withDate(int year, int month, int day) withDay(int day) withHour(int hour) withMillisecond(int millisecond) withMinute(int minute) withMonth(int month) withNano(int nano) withSecond(int second) withStartOfDay(boolean startOfDay) withTime(int hour, int minute, int second) withYear(int year) withZoneId(@NonNull ZoneId zoneId) intyear()year(int year) @NonNull ZoneIdzoneId()
-
Method Details
-
of
-
of
-
of
-
of
-
of
-
of
-
of
-
of
-
of
Create a date model out of a date string representation, in the format defined by eitherDateTimeFormatter.ISO_DATE_TIMEfor date-time orDateTimeFormatter.ISO_DATEfor date-only. If the time zone is not defined in the date string, UTC is assumed.- Parameters:
dateStr- date string- Returns:
- date model
- Throws:
DateTimeException- if the date string could not be parsed
-
of
public static DateModel of(@NonNull @NonNull String dateStr, @NonNull @NonNull ZonedDateTimeParser parser) Create a date model out of a date string representation, based on settings defined in the suppliedZonedDateTimeParser.- Parameters:
dateStr- date stringparser- the zoned date time parser- Returns:
- date model
- Throws:
DateTimeException- if the date string could not be parsed
-
withMillisecond
-
withDate
-
withTime
-
toDate
-
toEpoch
public long toEpoch() -
toInstant
-
toLocalDate
-
toLocalDateTime
-
toZonedDateTime
-
toString
Return the date as a string representation in the format defined byDateTimeFormatter.ISO_DATE_TIME. If the time zone is not defined, UTC is assumed.- Overrides:
toStringin classObject- Returns:
- date string
- Throws:
DateTimeException- if the date string could not be rendered as a string
-
year
public int year() -
month
public int month() -
day
public int day() -
hour
public int hour() -
minute
public int minute() -
second
public int second() -
nano
public int nano() -
zoneId
-
startOfDay
public boolean startOfDay() -
year
- Returns:
this.
-
month
- Returns:
this.
-
day
- Returns:
this.
-
hour
- Returns:
this.
-
minute
- Returns:
this.
-
second
- Returns:
this.
-
nano
- Returns:
this.
-
zoneId
- Returns:
this.
-
startOfDay
- Returns:
this.
-
equals
-
hashCode
public int hashCode() -
withYear
- Returns:
this.
-
withMonth
- Returns:
this.
-
withDay
- Returns:
this.
-
withHour
- Returns:
this.
-
withMinute
- Returns:
this.
-
withSecond
- Returns:
this.
-
withNano
- Returns:
this.
-
withZoneId
- Returns:
this.
-
withStartOfDay
- Returns:
this.
-