lu sheng
/
Nucleo_display_time
nucleo 070r display date &time
Diff: main.cpp
- Revision:
- 0:1e94dd911147
diff -r 000000000000 -r 1e94dd911147 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 19 06:03:34 2016 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" + +DigitalOut myled(LED1); + +int main() { + + printf("RTC example\n"); + //set_time(1387188300); // 起始时间Set RTC time to 16 December 2013 10:05:00 UTC + //从2013 10:05:00 开始计时 + //按秒调整时间 + //起始时间加一天即1387188300+86400 + //起始时间加一月即1387188300+2592000 按30天算 + //起始时间加一月即1387188300+31536000 按365天算 + //1476612300 + set_time(1476612300); // Sun Oct 16 10:05:53 2016 + + printf("Date and time are set.\n"); + + 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));//把time_t类型转换成字符串类型 + + //char buffer[32]; + //strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds)); + //printf("Time as a custom formatted string = %s", buffer); + + myled = !myled; + wait(1); + } +} \ No newline at end of file