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());

StartTime.postUpdate(currentDateTime.toString())

This should work in ECMAScript 5.1

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

Or this might even work:

StartTime.postUpdate(StartTime.state.getZonedDateTime().now());

In JSScripting

StartTime.postUpdate(time.ZonedDateTime.now().toString());

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