Mbed OS Reference
Loading...
Searching...
No Matches
mbed_rtc_time.h File Reference

Implementation of the C time.h functions. More...

#include <time.h>

Go to the source code of this file.

Data Structures

struct  timeval
 

Functions

void set_time (time_t t)
 Set the current time.
 
void attach_rtc (time_t(*read_rtc)(void), void(*write_rtc)(time_t), void(*init_rtc)(void), int(*isenabled_rtc)(void))
 Attach an external RTC to be used for the C time functions.
 
int gettimeofday (struct timeval *tv, void *tz)
 Standard lib retarget, get time since Epoch.
 
int settimeofday (const struct timeval *tv, const struct timezone *tz)
 Standard lib retarget, set time since Epoch.
 

Detailed Description

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 formatting functions.

Example:

#include "mbed.h"
int main() {
set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
while (true) {
time_t seconds = time(NULL);
printf("Time as seconds since January 1, 1970 = %u\n", (unsigned int)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);
ThisThread::sleep_for(1000);
}
}
void set_time(time_t t)
Set the current time.

Definition in file mbed_rtc_time.h.