Soo guys i need your help,
i want to compare two DateTimes with each other. So far so good.
if ( datemorning.isBefore((Sunrise_Time.state as DateTimeType).calendar.timeInMillis) ) {
executeCommandLine("/etc/openhab2/scripts/fksteck04.sh on")
postUpdate(FUNKD, "ON")
}
The problem is that datemorning needs to be a static DateTime of “06:00”.
Sure i could define a DateTime in the items file and call it with DateMorning.state but this is not the way i want to code this.
I’ve tried quite a few tricks but none of them worked.
For example:
val SimpleDateFormat sdf = new SimpleDateFormat("HH:mm")
val String timestampString = sdf.format("06:00")
val DateTimeType datemorning = DateTimeType.valueOf(timestampString)
or
var DateTime datemorning = new DateTime(( "06:00" as DateTimeType).calendar.timeInMillis)
or
SimpleDateFormat parseFormat = new SimpleDateFormat("HH:mm")
Date date = parseFormat.parse("06:00")
I only need the hours and minutes (“HH:mm”). No month or year!
So is there any way to cast the DateTime without to recall the state of an already existing DateTime in the items??