Difference between revisions of "Os.time"

From ComputerCraft Wiki
Jump to: navigation, search
(Changing number to number)
m (Fixed/Expanded)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=os.time
 
|name=os.time
|returns={{type|number}} The current in-game time.
+
|returns={{type|number}} the current in-game time
 
|api=OS
 
|api=OS
 
|addon=ComputerCraft
 
|addon=ComputerCraft
Line 9: Line 9:
 
{{Example
 
{{Example
 
|desc=Prints current time in 12 hour format (with AM and PM).
 
|desc=Prints current time in 12 hour format (with AM and PM).
|code=local time = os.time()<br/>time = textutils.formatTime(time, false)<br/>print("The time is "..time)
+
|code=local time = '''os.time()'''
}}
+
local formattedTime = [[textutils.formatTime]](time, false)
{{Example
+
|desc=Prints current time in 24 hour format.
+
[[print]]("The time is " .. formattedTime)
|code=local time = os.time()<br/>time = textutils.formatTime(time, true)<br/>print("The time is "..time)
+
 
}}
 
}}
 
|notes=
 
|notes=
* You must use textutils.formatTime() if you want to print the time in readable form.
+
* You should use [[textutils.formatTime]]() if you want to print the time in readable form.
 
}}
 
}}
  
 
[[Category:Lua_Core_Functions]]
 
[[Category:Lua_Core_Functions]]

Revision as of 22:38, 3 June 2014


Grid Redstone.png  Function os.time
Returns the current in-game time.
Syntax os.time()
Returns number the current in-game time
Part of ComputerCraft
API OS

Examples

Grid paper.png  Example
Prints current time in 12 hour format (with AM and PM).
Code
local time = os.time()
local formattedTime = textutils.formatTime(time, false)

print("The time is " .. formattedTime)

Additional Notes