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

Problem With os.time()

Started by Grim, 15 September 2017 - 05:04 AM
Grim #1
Posted 15 September 2017 - 07:04 AM
Hello I'm Having a Problem With The os.time() The Time It Displays Is Wrong.


Lets Say The Time Is 8:11 With The Time Program But The os.time() Says Its 20:312 And I Have Journey Map Installed And Its Says Its 11:55 I Don't Know What's Going On With The Code.

Is There Another Way To Display The Correct Time On A Monitor?

I'm Trying To Display The Time On The Reactor Monitor It Works But The Time Is Wrong.

Here Is The Code.

Spoiler
while true do
  local reactor1 = peripheral.wrap("BigReactors-Reactor_0")
  local mon = peripheral.wrap("monitor_0")
  local time = os.time()
  mon.clear()

  -- Begin Reactor 1
  mon.setCursorPos(1,8)
  mon.setTextColor(colors.yellow)
  mon.write(time)

  mon.setCursorPos(1,1)
  mon.setTextColor(colors.white)
  mon.write("Reactor #: ")
  mon.setTextColor(colors.lime)
  mon.write("1")

  mon.setCursorPos(1,2)
  mon.setTextColor(colors.white)
  mon.write("Active: ")
  mon.setTextColor(colors.lime)
  mon.write(reactor1.getActive())

  mon.setCursorPos(1,3)
  mon.setTextColor(colors.white)
  mon.write("RF/T: ")  
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getEnergyProducedLastTick()))

  mon.setCursorPos(1,4)
  mon.setTextColor(colors.white)
  mon.write("RF Stored: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getEnergyStored()))

  mon.setCursorPos(1,5)
  mon.setTextColor(colors.white)
  mon.write("Casing Heat: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getCasingTemperature()))

  mon.setCursorPos(1,6)
  mon.setTextColor(colors.white)
  mon.write("Fuel Heat: ")
  mon.setTextColor(colors.lime)
  mon.write(math.floor(reactor1.getFuelTemperature()))
  -- End Reactor 1

 sleep(1)
end
Edited on 15 September 2017 - 11:43 PM
Dave-ee Jones #2
Posted 18 September 2017 - 01:01 AM
Try this:

textutils.formatTime(os.time())

This sets it in a format like so:

11:56 PM

Keep in mind it's Minecraft time not IRL time.
KingofGamesYami #3
Posted 18 September 2017 - 02:24 AM
If you want IRL time, you'll need to query some sort of online api (assuming the mod's config allows it).
Lupus590 #4
Posted 18 September 2017 - 11:24 AM
If you want IRL time, you'll need to query some sort of online api (assuming the mod's config allows it).

Unless you are running the latest beta or one of the unofficial builds, then you have this as an option too: https://github.com/dan200/ComputerCraft/pull/183