How to display local time in my dashboard

I see there is ArduinoCloud.getLocalTime(); which I believe returns a FLOAT value, (epoch).

How can I display local date and time in the dashboard?

check if it is a Date_Time format "Unix" wich count time in elapsed seconds since 1970.
Obvioulsy, it won't return you a clean data in MM/DD/YY but you can convert it easily.

try first with a web converter or even in a excel/google sheet.

Pretty sure arduino has a dedicated function for this (so you can include it in your code) but I don't know it.

EDIT : see there: https://www.unixtimestamp.com/

Thanks for the link, yes I'm getting a Unix datetime value.
Arduino Cloud IDE has a variable type 'Time' which I'm using and get a display of '1.678628e +9'
What is the best way to convert it to mm/dd etc?

find some stuff around here. for examples:

EDIT: you may of course prefer the hardest way (typical school exercise)

60 seconds in a minute;
60 minutes in one hour;
24 hours a day etc
so how many seconds in a year (and don't forget the years with a 28th frebruary!) that you can divide your time_stamp with, then convert it back to get the year, the month etc....

-> use the time library as advised in the link.

OK, got it!

time_t UnixTime;
UnixTime = ArduinoCloud.getLocalTime();
myTimeVariable = ctime(&UnixTime);

myTimeVariable is a string that now has fully formatted time

:+1:

You can also just link UnixTime to the Time Picker widget.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.