Hey there,
in my openHAB 1.8.2 configuration I have a String item named Date_Raw which gets updated with a UTC time/date string (from an MQTT source). I have another DateTime item named Date_Local which should be the “local time” version of the previously mentioned UTC item (currently UTC+2 as we have DST). The problem is I’m not sure how to do the conversion.
At the moment my rule is only converting from String to DateTime, without doing any time conversion at all:
rule "Date changed"
when
Item Date_Raw changed
then
var SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss")
var DateTime dt = new DateTime(sdf.parse(Date_Raw.state.toString))
var DateTimeType dtt = new DateTimeType()
dtt.calendar.setTime(dt.toDate)
Date_Local.postUpdate(dtt)
end
Well I know that it could be simplified by using Date instead of DateTime but I thought for the timezone conversion DateTimeZone could help. I’ve played around with it but e.g. using DateTimeZone::UTC results in a NullPointerException.
How to do it correctly?
Thanks in advance.