Advertisement
levshx

TimeHost

Jan 19th, 2021 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. local fs = require("filesystem")
  2.  
  3. function getHostTime(timezone) --Получить текущее реальное время компьютера, хостящего сервер майна
  4. timezone = timezone or 2
  5. local file = io.open("/HostTime.tmp", "w")
  6. file:write("123")
  7. file:close()
  8. local timeCorrection = timezone * 3600
  9. local lastModified = tonumber(string.sub(fs.lastModified("/HostTime.tmp"), 1, -4)) + timeCorrection
  10. fs.remove("HostTime.tmp")
  11. local year, month, day, hour, minute, second = os.date("%Y", lastModified), os.date("%m", lastModified), os.date("%d", lastModified), os.date("%H", lastModified), os.date("%M", lastModified), os.date("%S", lastModified)
  12. return tonumber(day), tonumber(month), tonumber(year), tonumber(hour), tonumber(minute), tonumber(second)
  13. end
  14.  
  15.  
  16. function time(timezone) --Получет настоящее время, стоящее на Хост-машине
  17. local time = {getHostTime(timezone)}
  18. local text = string.format("%02d:%02d:%02d", time[4], time[5], time[6])
  19. return text
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement