Advertisement
uriid1

How many seconds until the next day with UTC. LUA

Jul 25th, 2022 (edited)
1,408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | None | 0 0
  1. local utc = 2
  2. local one_day = 86400 -- 60*60*24
  3.  
  4. local function set_hours(tbl_date, h, m, s)
  5.    tbl_date.hour = h
  6.    tbl_date.min  = m
  7.    tbl_date.sec  = s
  8.    return os.time(tbl_date)
  9. end
  10.  
  11. local current_time = os.time() + (utc*60*60) -- Time with UTC
  12. local current_day = os.date('*t', current_time)
  13. local clear_date = set_hours(current_day, 0, 0, 0)
  14. local next_day_date = clear_date + one_day
  15. local sec_to_next_day = next_day_date - current_time
  16.  
  17. -- Test
  18. print('UTC', utc)
  19. print('Sec to next day', sec_to_next_day)
  20. print('Today', os.date('%c', os.time(current_day)))
  21. print('Next', os.date('%c', current_time + sec_to_next_day))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement