Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local year = 2025
- local month = 1
- local day = 1
- local hour = 0
- local minute = 0
- local second = 0
- local function is_leap_year(year)
- if (year % 4 == 0 and year % 100 ~= 0) or (year % 400 == 0) then
- return true
- else
- return false
- end
- end
- local function days_in_month(month, year)
- local days_in_months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
- if month == 2 and is_leap_year(year) then
- return 29
- else
- return days_in_months[month]
- end
- end
- local function days_since_epoch(year, month, day, hour, minute, second)
- local days = 0
- for y = 1970, year - 1 do
- if is_leap_year(y) then
- days = days + 366
- else
- days = days + 365
- end
- end
- for m = 1, month - 1 do
- days = days + days_in_month(m, year)
- end
- days = days + (day - 1)
- local total_seconds = days * 86400
- total_seconds = total_seconds + (hour * 3600)
- total_seconds = total_seconds + (minute * 60)
- total_seconds = total_seconds + second
- return total_seconds
- end
- local epochTime = days_since_epoch(year, month, day, hour, minute, second)
- print(epochTime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement