How do I publish the current time?

I know that code running on a Particle device can retrieve and sync the current date and time from the Particle Cloud. But I have not been able to find an example in the docs of how to parse and then publish selected components of the current time (hours, minutes, etc.) so that they can be logged into a Google sheet via IFTTT (IFTTT’s date and time stamp is a single string of variable length that has to be parsed via a complex formula after each event is added to the sheet).

Can anyone point me to a tutorial or example of how to send the individual date and time elements as separate data items?

First you’d need to decide on which format you want to transfer,
Many programs can readily collect UNIX Epoch timestamps, which is what you get from Time.now() or Time.local().
However, if you want to send the timestamp in a human readable representation then you may want to have a look at Time.format()

Geeze ScruffR, do you ever sleep? Thanks.

Yes, I want it to be readable by a human. I think I understand how I can format the time. What I can’t figure out is how to set a variable to a specific component of the current time. For example, let’s say I just want to publish the current hour; I’d like to set variable ‘Hour’ to the current hour and then, via Particle.publish, send ‘Hour’ to the cloud and then, via IFTTT, add it to a Google sheet.

1 Like

Oops; I think I figured it out:
Hour = Time.hour();
Right?

Correct!
Or you follow the link referenced in the Time.format() section that helps you create a format string that matches your needs
http://www.cplusplus.com/reference/ctime/strftime/

e.g. Time.format("%H:%M") will give you a string like 23:59

Perfect! Thanks again.

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