Logan Puppie
Logan Puppie

Reputation: 1

Getting the time in the format HH:MM:SS between the current time and a time from Trello

I'm currently able to get the Trello due date, giving me this string:

2018-10-22T16:00:00.000Z

I'd like to get the time until then in the format HH:MM:SS as a string.

With normal Lua, I imagine it wouldn't be too hard, but with the restricted use of things like os.time, I'm quite confused on how to do it. Thanks for any help!

Upvotes: 0

Views: 457

Answers (1)

wsha
wsha

Reputation: 964

string.match can extract your date and time, the following code will give you each value in a variable to use. reference:sting.match wiki

str = "2018-10-22T16:00:00.000Z"
-- Extract date
local year, month, day = str:match("(%d+)-(%d+)-(%d+)")
print(year, month, day) -- 2018, 10, 22
-- Extract Time
local hour, min, sec = str:match("(%d+):(%d+):(%d+)")
print(hour, min, sec) -- 16, 00, 00
-- or more like your requirement
print(string.format('%.2d:%.2d:%.2d', hour, min, sec)) -- 16:00:00

Upvotes: 1

Related Questions