Log the date and time

In this tutorial we show you how to run a simple data-logging program on your device. The program logs the current date and time, which can then be viewed in the Toit console or with the Toit CLI.

The following Toit program uses print to log the current date and time.

  time := Time.now.local
  print "Time: $(%02d time.h):$(%02d time.m)"
  print "Date: $(%04d time.year)-$(%02d time.month)-$(%02d time.day)"

Copy and paste the Toit program above into the Code tab of an online device, press the Run on device button and go to the Logs tab of the device to see the logged date and time that is sent from the device to the Toit console.

The Logs tab of your device shows the recent log entries. Check the "Application" to filter out logs to only display the ones generated by Toit applications.

The logs tab on the Toit console