he RTC (Real-Time Clock) class provides mechanisms to set the current time of the hardware RTC with set_time API. The time is set as an offset measured in seconds from the time epoch (Unix Epoch - January 1, 1970).

Dependencies:   mbed

Fork of RTC by Joël Imbaud

Files at this revision

API Documentation at this revision

Comitter:
jimbaud
Date:
Tue Jan 08 10:33:50 2019 +0000
Commit message:
he RTC (Real-Time Clock) class provides mechanisms to set the current time of the hardware RTC with set_time API. The time is set as an offset measured in seconds from the time epoch (Unix Epoch - January 1, 1970).

Changed in this revision

Main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main.cpp	Tue Jan 08 10:33:50 2019 +0000
@@ -0,0 +1,44 @@
+/*  https://os.mbed.com/docs/v5.7/reference/rtc.html
+    The RTC (Real-Time Clock) class provides mechanisms to set the current time of the hardware RTC with set_time API. The time is set as an offset measured in seconds from the time epoch (Unix Epoch - January 1, 1970).
+    
+    https://fr.wikipedia.org/wiki/Heure_Unix
+    
+    https://www.epochconverter.com/programming/c
+    
+    You can use the attach_rtc API to hook external RTC for using C time functions. It provides you with init(), read(), write() and isenabled() functions to be attached. Time provides more information about C date and time standard library functions.
+    RTC class APIs are thread safe. RTC can keep track of time even in a powered down state if the secondary source of power (battery) is connected.
+
+    https://os.mbed.com/blog/entry/103/
+    
+*/
+
+#include "mbed.h"
+
+int main() {
+
+                // Set the current time from the terminal
+
+            struct tm t;
+            printf("Enter current date and time:\n");
+            printf("YYYY MM DD HH MM SS[enter]\n");
+            scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
+
+                // Adjust for tm structure required values
+            t.tm_year = t.tm_year - 1900;
+            t.tm_mon = t.tm_mon - 1;
+                
+                // Set the time
+            set_time(mktime(&t));
+
+                // Display the time
+
+    while(1) {
+                time_t seconds = time(NULL);
+                printf("Time as a basic string = %s", ctime(&seconds));
+                wait(1);
+                char buffer[32];
+                strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
+                printf("Time as a custom formatted string = %s", buffer);
+                wait(1);
+            }
+        }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jan 08 10:33:50 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file