That wouldn’t do you any good since the call to .persist requires a ZonedDateTime; Persistence | openHAB
<item>.persist(ZonedDateTime, State) Persists a past or future state for the Item
Furthermore, a ZonedDateTime is a datetime Object so I’m not sure what other Object you are wanting to use instead.
Are the timezones the same in the DB entries that are different? I wouldn’t be surprised if MariaDB saves everything using UTC or even epoch but maybe it’s not consistent with the timezone.
Another way to create a date time of today at noon is:
The idea is that I run this regularly, and it updates my electricity generated amount during the day.
I want just a single value persisted in my DB for each day, and I want this to be at midday which aligns nicely in a bar chart analyze.
Each time I run the above blockly, the milliseconds persisted are different:
2025-05-02 18:19:50.887 [INFO ] [ation.script.ui.UpdateDailyGenerated] - Updating Daily KwH Generation, delta is: 3.551 kWh at:2025-05-02T12:00:00.876+02:00[Europe/Zurich]
2025-05-02 18:24:53.177 [INFO ] [ation.script.ui.UpdateDailyGenerated] - Updating Daily KwH Generation, delta is: 3.551 kWh at:2025-05-02T12:00:00.166+02:00[Europe/Zurich]
This looks like the set 0 milli is not working.
I tried different combinations (just milli, just nano etc.)
In the mean time, you can try to make it work using the block you originally used (that should work too) or use an inline script block with midday = time.toZDT("12:00");
var midday;
midday = (time.ZonedDateTime.now()).withHour(12);
midday = midday.withHour(12);
midday = midday.withMinute(0);
midday = midday.withSecond(0);
midday = midday.withNano(1000000);
midday = midday.withNano(1000);
midday = midday.withNano(1);
midday = midday;
midday = midday;
midday = midday;
console.log(midday);```
So, the micro, nano and milli work fine for non zero values, but fail for 0.
However, for my purposes to store 12:00:00.000 to my persistence service this is good enough.
If I specify withNano(1) it produces this, and when rounded to 3 DP it works well.
2025-05-04T12:00:00.000000001+02:00[Europe/Zurich]