Small test of the gmtime function.

Dependencies:   mbed

Committer:
bjblazkowicz
Date:
Sun May 10 22:05:28 2015 +0000
Revision:
0:53c251120904
Initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bjblazkowicz 0:53c251120904 1 #include "mbed.h"
bjblazkowicz 0:53c251120904 2 #include "gmtime_newlib.h"
bjblazkowicz 0:53c251120904 3
bjblazkowicz 0:53c251120904 4 Serial console(USBTX, USBRX);
bjblazkowicz 0:53c251120904 5
bjblazkowicz 0:53c251120904 6 int main()
bjblazkowicz 0:53c251120904 7 {
bjblazkowicz 0:53c251120904 8 console.baud(9600);
bjblazkowicz 0:53c251120904 9
bjblazkowicz 0:53c251120904 10 // Set time to Tue, 10 Nov 2015 14:00:00 GMT
bjblazkowicz 0:53c251120904 11 set_time(1447164000);
bjblazkowicz 0:53c251120904 12
bjblazkowicz 0:53c251120904 13 time_t rawTime;
bjblazkowicz 0:53c251120904 14 time(&rawTime);
bjblazkowicz 0:53c251120904 15
bjblazkowicz 0:53c251120904 16 // Prints: time_t: 1447164000, h:13773, m:1377, s:537067520
bjblazkowicz 0:53c251120904 17 struct tm *parsedUsingMbed = gmtime(&rawTime);
bjblazkowicz 0:53c251120904 18 console.printf("time_t: %d, h:%d, m:%d, s:%d\r\n", rawTime, parsedUsingMbed->tm_hour, parsedUsingMbed->tm_min, parsedUsingMbed->tm_sec);
bjblazkowicz 0:53c251120904 19
bjblazkowicz 0:53c251120904 20 // Prints: time_t: 1447164000, h:14, m:0, s:0
bjblazkowicz 0:53c251120904 21 struct tm parsedUsingNewlib;
bjblazkowicz 0:53c251120904 22 gmtime_newlib(&rawTime, &parsedUsingNewlib);
bjblazkowicz 0:53c251120904 23 console.printf("time_t: %d, h:%d, m:%d, s:%d\r\n", rawTime, parsedUsingNewlib.tm_hour, parsedUsingNewlib.tm_min, parsedUsingNewlib.tm_sec);
bjblazkowicz 0:53c251120904 24
bjblazkowicz 0:53c251120904 25 while(1)
bjblazkowicz 0:53c251120904 26 ;
bjblazkowicz 0:53c251120904 27 }