Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is this New Years Timer printing 1970 and not 2019?

Asked by 5 years ago

I'm making a New Year Countdown timer but my whole script is completely off. When I try to print this code it prints out the year as 1970 and not 2019 and I have no clue why this is happening.

local new_years_date = os.time({
    year = 2019;
    month = 1;
    day = 1;
    hour = 0;
    minute = 0;
    sec = 0;
})



local diffTime = os.difftime(new_years_date, os.time())
local tab = os.date('!*t', diffTime)

for k, v in pairs(tab) do
    print(k, v)
end

OUTPUT: (look at the year)

hour 10 min 17 wday 7 day 3 month 1 year 1970 sec 44 yday 3

0
I answered this question iiDev_Hunt3r 64 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You put

local diffTime = os.difftime(new_years_date, os.time())

when you don't need to because new_years_date is already os.time . So here's the working script that prints the correct dates you want it to.

local new_years_date = os.time({
    year = 2019;
    month = 1;
    day = 1;
    hour = 0;
    minute = 0;
    sec = 0
})



local diffTime = os.difftime(new_years_date)
local tab = os.date('!*t', diffTime)

for k, v in pairs(tab) do
    print(k, v)
end
Ad

Answer this question