Difference between revisions of "Textutils.formatTime"
From ComputerCraft Wiki
(Changing int to number) |
MKlegoman357 (Talk | contribs) (Updated/Improved) |
||
Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=textutils.formatTime | |name=textutils.formatTime | ||
− | |args= {{type|number}} time, {{type|boolean}} | + | |args= {{type|number}} time, {{type|boolean}} twentyFourHour |
|returns={{type|string}} formatted time | |returns={{type|string}} formatted time | ||
|api=textutils | |api=textutils | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc= | + | |desc=Takes input <var>time</var> and formats it in a more readable format. If the second value is <var>true</var>, returns time in twenty-four hour format; if the second value is <var>false</var>, returns time in twelve-hour format, with AM or PM. Default for <var>twentyFourHour</var> is <var>false</var>. |
|examples= | |examples= | ||
{{Example | {{Example | ||
|desc=Prints the Minecraft world time in 12-hour time. | |desc=Prints the Minecraft world time in 12-hour time. | ||
− | |code=print(textutils.formatTime(os.time(), false)) | + | |code=[[print]]( '''textutils.formatTime( [[os.time]](), false )''' ) |
|output=Depends on the time of day in your world, it will look something like this: "5:30 AM". | |output=Depends on the time of day in your world, it will look something like this: "5:30 AM". | ||
}} | }} | ||
Line 16: | Line 16: | ||
{{Example | {{Example | ||
|desc=Prints the Minecraft world time in 24-hour time. | |desc=Prints the Minecraft world time in 24-hour time. | ||
− | |code=print(textutils.formatTime(os.time(), true)) | + | |code=[[print]]( '''textutils.formatTime( [[os.time]](), true )''' ) |
|output=Depends on the time of day in your world, it will look something like this: "17:30". | |output=Depends on the time of day in your world, it will look something like this: "17:30". | ||
}} | }} |
Latest revision as of 20:48, 16 February 2015
Function textutils.formatTime | |
Takes input time and formats it in a more readable format. If the second value is true, returns time in twenty-four hour format; if the second value is false, returns time in twelve-hour format, with AM or PM. Default for twentyFourHour is false. | |
Syntax | textutils.formatTime(number time, boolean twentyFourHour) |
Returns | string formatted time |
Part of | ComputerCraft |
API | textutils |
Examples
Example | |
Prints the Minecraft world time in 12-hour time. | |
Code |
print( textutils.formatTime( os.time(), false ) ) |
Output | Depends on the time of day in your world, it will look something like this: "5:30 AM". |
Example | |
Prints the Minecraft world time in 24-hour time. | |
Code |
print( textutils.formatTime( os.time(), true ) ) |
Output | Depends on the time of day in your world, it will look something like this: "17:30". |