Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wrap the monitor on the right side
- local monitor = peripheral.wrap("right")
- -- Function to convert in-game days to a calendar date
- local function convertToDate(day)
- local year = math.floor((day - 1) / 365) + 1
- local dayOfYear = (day - 1) % 365 + 1
- local months = {
- {name = "January", days = 31},
- {name = "February", days = 28},
- {name = "March", days = 31},
- {name = "April", days = 30},
- {name = "May", days = 31},
- {name = "June", days = 30},
- {name = "July", days = 31},
- {name = "August", days = 31},
- {name = "September", days = 30},
- {name = "October", days = 31},
- {name = "November", days = 30},
- {name = "December", days = 31},
- }
- local month = 1
- local dayOfMonth = dayOfYear
- for i, m in ipairs(months) do
- if dayOfMonth <= m.days then
- month = i
- break
- end
- dayOfMonth = dayOfMonth - m.days
- end
- return dayOfMonth, month, year
- end
- -- Function to print the current time and date
- local function printTimeAndDate()
- -- Clear the monitor
- monitor.clear()
- monitor.setCursorPos(1, 1)
- -- Get the current time and date
- local time = os.time()
- local day = os.day()
- -- Convert the in-game day to a calendar date
- local dayOfMonth, month, year = convertToDate(day)
- -- Format the time (in-game time from 0 to 24)
- local hours = math.floor(time)
- local minutes = math.floor((time - hours) * 60)
- -- Print the date and time on the monitor
- monitor.write(string.format("Date: %02d/%02d/%03d", dayOfMonth, month, year))
- monitor.setCursorPos(1, 2)
- monitor.write(string.format("Time: %02d:%02d", hours, minutes))
- end
- -- Main loop to update the time and date every second
- while true do
- printTimeAndDate()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement