thedumbone
thedumbone

Reputation: 21

os.time prints formatted date rather than number

I'm just wondering what could be the reason for this line to return a formatted string

    print(os.time{year=2018, month=11, day=11, hour=11})

returns 2018-11-11 11:00:00

where if I go to lua demo it returns date in numbers

is that a reason because of system difference? What can I do to get these numbers? My main goal is to add certain of days to the date. In following format :

oldDate + (60*60*24*daysToAdd)

Upvotes: 0

Views: 256

Answers (1)

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23767

Probably you still can add days despite of non-standard os.time.
Try

local dt = os.date("*t") -- today 
print(dt.day, dt.month)  -- 28 nov
dt.day = dt.day + 111    -- add 111 days
dt = os.date("*t", os.time(dt))
print(dt.day, dt.month)  -- 19 mar

Does it print March 19 ?

Upvotes: 1

Related Questions