Advertisement
devomaa

Time API

May 22nd, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. --Time API
  2. if not switchcraft then
  3. os.loadAPI("json")
  4. end
  5. --timezone is for an example: Europe/Helsinki
  6. function getTime(timezone, x, y)
  7. local obj = http.get("http://worldtimeapi.org/api/timezone/"..timezone).readAll()
  8. local tbl = json.decode(obj)
  9. local ts = tbl.unixtime+tbl.dst_offset
  10. term.clearLine()
  11. x,y = term.getCursorPos()
  12. term.setCursorPos(x,y)
  13. term.write(os.date('%Y-%m-%d %H:%M:%S', ts))
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement