nucleo 070r display date &time

Dependencies:   mbed

main.cpp

Committer:
anywill
Date:
2016-10-19
Revision:
0:1e94dd911147

File content as of revision 0:1e94dd911147:

#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);
    }
}