Time

This content relates to a deprecated version of Mbed

Mbed 2 is now deprecated. For the latest version please see the Mbed OS documentation.

For the latest Time API, please see Time.

Import program

00001 #include "mbed.h"
00002 
00003 int main() {
00004     set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
00005 
00006     while (true) {
00007         time_t seconds = time(NULL);
00008         
00009         printf("Time as seconds since January 1, 1970 = %d\n", seconds);
00010         
00011         printf("Time as a basic string = %s", ctime(&seconds));
00012 
00013         char buffer[32];
00014         strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
00015         printf("Time as a custom formatted string = %s", buffer);
00016         
00017         wait(1);
00018     }
00019 }

/** Implementation of the C time.h functions
 *
 * Provides mechanisms to set and read the current time, based
 * on the microcontroller Real-Time Clock (RTC), plus some
 * standard C manipulation and formating functions.
 *
 * Example:
 * @code
 * #include "mbed.h"
 *
 * int main() {
 *     set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
 *
 *     while(1) {
 *         time_t seconds = time(NULL);
 *
 *         printf("Time as seconds since January 1, 1970 = %d\n", seconds);
 *
 *         printf("Time as a basic string = %s", ctime(&seconds));
 *
 *         char buffer[32];
 *         strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
 *         printf("Time as a custom formatted string = %s", buffer);
 *
 *         wait(1);
 *     }
 * }
 * @endcode
 */
 
/** Set the current time
 *
 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
 * to the time represented by the number of seconds since January 1, 1970
 * (the UNIX timestamp).
 *
 * @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
 *
 * Example:
 * @code
 * #include "mbed.h"
 *
 * int main() {
 *     set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
 * }
 * @endcode
 */

Time with the FRDM-KL25Z

For the FRDM-KL25Z board, the on-board oscillator does not allow to use the RTC module. We instead generate the RTC clock from the interface chip on the RTC_CLKIN pin (PTC1). That is why the PTC1 pin is not available for other purpose.


All wikipages