6

How can I get the current UTC time using a Lua script and convert it to human readable text?

1 Answer 1

25

Try os.date("!%c"). Here ! means UTC and %c means full date in standard format. For other options, see http://www.lua.org/manual/5.2/manual.html#pdf-os.date.

curTime = os.time(); print("os.date(): "..os.date('%Y-%m-%d-%H:%M:%S', curTime));  
print("os.date(!): "..os.date('!%Y-%m-%d-%H:%M:%S GMT', curTime))
2
  • Thanks for the answer, here is some sample code that expands on the use of !: cutTime = os.time(); print("os.date(): "..os.date('%Y-%m-%d-%H:%M:%S', curTime)); print("os.date(!): "..os.date('!%Y-%m-%d-%H:%M:%S GMT', curTime)) Oct 19, 2017 at 17:50
  • @TzunghsingDavidWong - Please edit the answer to incorporate your comment into it. Comments get deleted many times. Mar 26, 2021 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.