Advertisement
Rochet2

Get diff in seconds from now to date time

Sep 8th, 2014
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. --[[
  2. Get diff in seconds from now to date time by
  3. Laurea
  4. Foereaper
  5. Rochet2
  6. ]]
  7.  
  8. local d = os.date("*t")
  9.  
  10. -- Set desired time here
  11. d.sec = 0
  12. d.min = 30
  13. d.hour = 15
  14. -- 1 = mon, 2 = tue ..
  15. local weekday = 2
  16.  
  17. local ddiff = weekday-d.wday+1
  18. d.day = d.day+ddiff
  19. local now = os.date("*t")
  20. if (ddiff < 0) then
  21. -- Take into consideration that it is tuesday and we want monday
  22.     d.day = d.day+7
  23. elseif (ddiff == 0 and d.hour*60*60+d.min*60+d.sec < now.hour*60*60+now.min*60+now.sec) then
  24. -- Take into consideration that it is the same date, but its already past the wanted time
  25.     d.day = d.day+7
  26. end
  27. -- get final times
  28. local e = os.time(d)
  29. local diff = e-os.time() -- this is the time in seconds until the wanted date is achieved
  30.  
  31. -- test print
  32. print(os.date("%c", os.time()+diff))
  33. print(os.date("%c"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement