[SOLVED] Openhab DateTime


i am sure that is whas written 1 mio times, i have read it und do not understand.

I have Item

DateTime TestDateTime "Test DateTime"  

I have rule with which i would like to put current datetime in item

rule "Test DateTime"
    Time cron "0/2 * * * * ?"
    val nowDateTime = (now)
    logInfo("asrto.rules", "nowDateTime: " + nowDateTime)

And i get error

2019-10-24 11:46:14.012 [INFO ] [e.smarthome.model.script.asrto.rules] - nowDateTime: 2019-10-24T11:46:14.009+02:00

2019-10-24 11:46:14.016 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Test DateTime': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,org.eclipse.smarthome.core.types.State) on instance: null

But why, is this DateTIme format wrong for Openahab item?
Here https://www.openhab.org/docs/configuration/items.html#type i can see only word “Stores date and time” but in whioch format!?

Thanks a lot!

Just a shot in the dark but don’t you (the user) define the format?
Example form the Docs

DateTime  Livingroom_TV_LastUpdate "Last Update [%1$ta %1$tR]"         // e.g. "Sun 15:26"

A working way to do this
TestDateTime.postUpdate(new DateTimeType()) // defaults to now

1 Like