Reputation: 181
This is a piece of lua script that displays the time. I cannot separate the numbers ie: time.hour, ":"
,
to basically show hh:mm:ss
time = os.date("*t")
print(time.hour .. time.min .. time.sec)
Upvotes: 11
Views: 24257
Reputation: 21
local date = os.date('*t')
local time = os.date("*t")
print(os.date("%A, %m %B %Y | "), ("%02d:%02d:%02d"):format(time.hour, time.min, time.sec))`
Upvotes: 2
Reputation: 499
For simply printing the time - extract what you want (the time) from the full date stamp string:
> os.date():sub(9)
12:30:39
This works on my PC ;). There may be a different date stamp string in your OS.
G
Upvotes: 2
Reputation: 26744
There are several ways to do this:
Use string concatenation: print(time.hour .. ":" .. time.min .. ":" .. time.sec)
Use formatting: print(("%02d:%02d:%02d"):format(time.hour, time.min, time.sec))
Use table concatenation: print(table.concat({time.hour, time.min, time.sec}, ":"))
When you really need to format your string, my preference would be for #2. For time = {hour = 1, min = 20, sec = 5}
this prints:
1:20:5
01:20:05
1:20:5
Upvotes: 10