Display current time  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Display current time  [Solved]

Post 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)
Last edited by HvdW on Saturday 04 November 2023 15:38, edited 1 time in total.
Bugs bug me.
willemd
Posts: 649
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Display current time

Post 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)
Kedi
Posts: 575
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Display current time

Post by Kedi »

dzVents has a time object that can do a lot of things easier.
https://www.domoticz.com/wiki/DzVents:_ ... ime_object
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest