Printf and Time.format syntax

The following works, but … Time.format output won’t print as a %s within the printf statement.

            Serial.printf("Sunrise = %d = ", sr);
            Serial.println(Time.format(sr, TIME_FORMAT_DEFAULT));

Can anyone point me to documentation that explains the datatype returned by Time.format?

@Bear, try this, assuming that sr is of type “time_t” and contains data assigned by something like:

time_t sr = Time.now();

Serial.println((const char *) Time.format(sr, TIME_FORMAT_DEFAULT));

Time.format() returns a String object.
To convert that into a const char* you can either use the (undocumented) typcast overload suggested by @syrinxtech or the dedicated conversion function StringClass::c_str() or create a copy of the string via StringClass::toCharArray().
I personally prefer the typecast.

https://docs.particle.io/reference/firmware/photon/#string-class

1 Like