Class DateTimeType

java.lang.Object
org.openhab.core.library.types.DateTimeType
All Implemented Interfaces:
Comparable<DateTimeType>, Command, PrimitiveType, State, Type

@NonNullByDefault public class DateTimeType extends Object implements PrimitiveType, State, Command, Comparable<DateTimeType>
Author:
Kai Kreuzer - Initial contribution, Erdoan Hadzhiyusein - Refactored to use ZonedDateTime, Jan N. Klug - add ability to use time or date only, Wouter Born - increase parsing and formatting precision, Laurent Garnier - added methods toLocaleZone and toZone, Gaƫl L'hopital - added ability to use second and milliseconds unix time, Jimmy Tanagra - implement Comparable, Jacob Laursen - Refactored to use Instant internally
  • Field Details

  • Constructor Details

    • DateTimeType

      public DateTimeType()
      Creates a new DateTimeType representing the current instant from the system clock.
    • DateTimeType

      public DateTimeType(Instant instant)
      Creates a new DateTimeType with the given value.
      Parameters:
      instant -
    • DateTimeType

      public DateTimeType(ZonedDateTime zoned)
      Creates a new DateTimeType with the given value. The time-zone information will be discarded, only the resulting Instant is preserved.
      Parameters:
      zoned -
    • DateTimeType

      public DateTimeType(String zonedValue)
  • Method Details

    • getZonedDateTime

      @Deprecated public ZonedDateTime getZonedDateTime()
      Deprecated.
      Get object represented as a ZonedDateTime with system default time-zone applied
      Returns:
      a ZonedDateTime representation of the object
    • getZonedDateTime

      public ZonedDateTime getZonedDateTime(ZoneId zoneId)
      Get object represented as a ZonedDateTime with the the provided time-zone applied
      Returns:
      a ZonedDateTime representation of the object
    • getInstant

      public Instant getInstant()
      Get the Instant value of the object
      Returns:
      the Instant value of the object
    • valueOf

      public static DateTimeType valueOf(String value)
    • format

      public String format(@Nullable String pattern)
      Description copied from interface: Type
      Formats the value of this type according to a pattern (see Formatter).
      Specified by:
      format in interface Type
      Parameters:
      pattern - the pattern to use
      Returns:
      the formatted string
    • format

      public String format(@Nullable String pattern, ZoneId zoneId)
    • format

      public String format(Locale locale, String pattern)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toFullString

      public String toFullString()
      Description copied from interface: Type
      Get a string representation that contains the whole internal representation of the type.

      The returned string could be consumed by the static 'valueOf(String)' method of the respective type to build a new type that is equal to this type.

      Specified by:
      toFullString in interface Type
      Returns:
      a full string representation of the type to be consumed by 'valueOf(String)'
    • toFullString

      public String toFullString(ZoneId zoneId)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(DateTimeType o)
      Specified by:
      compareTo in interface Comparable<DateTimeType>