diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java index 27056e8328b..ba9d93f1709 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/DateTimeValue.java @@ -12,6 +12,8 @@ */ package org.openhab.binding.mqtt.generic.values; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.List; @@ -45,11 +47,12 @@ public class DateTimeValue extends Value { @Override public String getMQTTpublishValue(Command command, @Nullable String pattern) { + ZonedDateTime zonedDateTime = ((DateTimeType) command).getZonedDateTime(ZoneId.systemDefault()); String formatPattern = pattern; if (formatPattern == null || "%s".contentEquals(formatPattern)) { - return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(((DateTimeType) command).getZonedDateTime()); + return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(zonedDateTime); } - return String.format(formatPattern, ((DateTimeType) command).getZonedDateTime()); + return String.format(formatPattern, zonedDateTime); } @Override