Class DateTimeType

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

@NonNullByDefault public class DateTimeType extends Object implements PrimitiveType, State, Command
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
  • Field Details

  • Constructor Details

    • DateTimeType

      public DateTimeType()
    • DateTimeType

      public DateTimeType(ZonedDateTime zoned)
    • DateTimeType

      public DateTimeType(String zonedValue)
  • Method Details

    • getZonedDateTime

      public ZonedDateTime getZonedDateTime()
    • getInstant

      public Instant getInstant()
      Get curent object represented as an Instant
      Returns:
      an Instant representation of the current 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(Locale locale, String pattern)
    • toLocaleZone

      public DateTimeType toLocaleZone() throws DateTimeException, ZoneRulesException
      Create a DateTimeType being the translation of the current object to the locale time zone
      Returns:
      a DateTimeType translated to the locale time zone
      Throws:
      DateTimeException - if the converted zone ID has an invalid format or the result exceeds the supported date range
      ZoneRulesException - if the converted zone region ID cannot be found
    • toZone

      Create a DateTimeType being the translation of the current object to a given zone
      Parameters:
      zone - the target zone as a string
      Returns:
      a DateTimeType translated to the given zone
      Throws:
      DateTimeException - if the zone has an invalid format or the result exceeds the supported date range
      ZoneRulesException - if the zone is a region ID that cannot be found
    • toZone

      public DateTimeType toZone(ZoneId zoneId) throws DateTimeException
      Create a DateTimeType being the translation of the current object to a given zone
      Parameters:
      zoneId - the target ZoneId
      Returns:
      a DateTimeType translated to the given zone
      Throws:
      DateTimeException - if the result exceeds the supported date range
    • 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)'
    • hashCode

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

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