ECMAScript postUpdate to a DateTime Object

Hi *,

I think I’m starting to loose it as I can somehow not manage (for several hours now) to set a DateTime Item.

I got a scheduled script that executes on three o’clock that should set a DateTime Item.
All I want to do, is to set a JavaScript Date() object as value for a Item.

var StartTime = itemRegistry.getItem("StartTime");
StartTime.postUpdate(new Date().toISOString());

I managed to get it working seconds after posting here…
Is this a good solution? I don’t know but it works!

var StartTime = itemRegistry.getItem("StartTime");
var dateTimeType = Java.type('org.openhab.core.library.types.DateTimeType');
var currentDateTime = new dateTimeType((new Date).toISOString());


This should work in ECMAScript 5.1

var ZonedDateTime = Java.type('java.time.ZonedDateTime');

Or this might even work:


In JSScripting


I’m not sure if the toString() is required or not.