Page 1 of 1

Display current time  [Solved]

Posted: Saturday 04 November 2023 0:23
by HvdW
I want to display the current time in the log using domoticz.log('Current time is : ' .. someTime, dz.LOG_INFO)
Just don't understand the Wiki.

Code: Select all

return {
	on = {
		timer = {'every minute'},
	},
	data = {},
	logging = {},
	execute = function(domoticz, triggeredItem)
	  
          domoticz.log('Current time is      : ' .. time_now, dz.LOG_INFO)
	end
}
What is the formula to create a timestring like time_now.

It took quite some time to find out, but here it is.

Code: Select all

dz.log('The current time is:  ' .. os.date("!%Y-%m-%d %T"), dz.LOG_INFO)
or

Code: Select all

dz.log('The current time is:  ' .. os.date("%c"), dz.LOG_INFO)

Re: Display current time

Posted: Saturday 04 November 2023 11:51
by willemd
Correct, took me some time as well.

As an addition: If you need for example the current time plus one hour, you can write:

Code: Select all

local NextHourDateTime=os.date("%Y-%m-%d %H:00:00",os.time() + 60*60)

Re: Display current time

Posted: Saturday 04 November 2023 16:20
by Kedi
dzVents has a time object that can do a lot of things easier.
https://www.domoticz.com/wiki/DzVents:_ ... ime_object