This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Tusillody's profile picture

Display actual time in-game?

Started by Tusillody, 18 July 2012 - 08:32 AM
Tusillody #1
Posted 18 July 2012 - 10:32 AM
Im working on a script for another server, and they want basically real time displayed on screen.

I can easily get the time of the server, using os.time() But I have no clue how to get real time.

Is it possible? And if so, how?
Exerro #2
Posted 18 July 2012 - 11:39 AM
os.clock() I think I.e.
k = os.clock()
print(k)
KaoS #3
Posted 18 July 2012 - 12:03 PM
I think you might have to use the http api to connect to a time server online, I haven't used that api so I am not sure but take a look
Jarle212 #4
Posted 18 July 2012 - 02:23 PM
t = os.clock()
print(textutils.formatTime(t,[false/true])


false = AM/PM true = 24h


Edit:
If you want the real time from you computer read this: http://www.lua.org/pil/22.1.html
1lann #5
Posted 18 July 2012 - 02:41 PM
t = os.clock()
print(textutils.formatTime(t,[false/true])


false = AM/PM true = 24h


Edit:
If you want the real time from you computer read this: http://www.lua.org/pil/22.1.html
That doesn't apply to ComputerCraft's OS API
Also os.clock() returns with the time since the computercraft computer you are using turned on.
Tusillody #6
Posted 18 July 2012 - 05:16 PM
Yeah, os.clock() shows time since the pc has been on. Ive never used the http api either, i have it enabled on the server though.
Lyqyd #7
Posted 19 July 2012 - 01:58 AM
Yes, this is possible. It's even been done before. You'll just have to click the stupid spoilers open. This isn't my code, so I can't vouch for it, but it claims to do what you're looking for.