set Unix timestamp: http://www.onlineconversion.com/unix_time.htm
Fork of time_HelloWorld by
main.cpp@1:62dbcc01f38a, 2013-09-18 (annotated)
- Committer:
- sandrojuca
- Date:
- Wed Sep 18 21:18:13 2013 +0000
- Revision:
- 1:62dbcc01f38a
- Parent:
- 0:b3b93997a0a6
Convert a Date/Time to a Unix timestamp: http://www.onlineconversion.com/unix_time.htm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:b3b93997a0a6 | 1 | #include "mbed.h" |
mbed_official | 0:b3b93997a0a6 | 2 | |
sandrojuca | 1:62dbcc01f38a | 3 | DigitalOut led(LED1); |
sandrojuca | 1:62dbcc01f38a | 4 | |
mbed_official | 0:b3b93997a0a6 | 5 | int main() { |
sandrojuca | 1:62dbcc01f38a | 6 | set_time(1379528015); // Set RTC time Unix timestamp: http://www.onlineconversion.com/unix_time.htm |
mbed_official | 0:b3b93997a0a6 | 7 | |
mbed_official | 0:b3b93997a0a6 | 8 | while (true) { |
mbed_official | 0:b3b93997a0a6 | 9 | time_t seconds = time(NULL); |
mbed_official | 0:b3b93997a0a6 | 10 | |
sandrojuca | 1:62dbcc01f38a | 11 | // printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
mbed_official | 0:b3b93997a0a6 | 12 | |
mbed_official | 0:b3b93997a0a6 | 13 | printf("Time as a basic string = %s", ctime(&seconds)); |
mbed_official | 0:b3b93997a0a6 | 14 | |
sandrojuca | 1:62dbcc01f38a | 15 | // char buffer[32]; |
sandrojuca | 1:62dbcc01f38a | 16 | // strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
sandrojuca | 1:62dbcc01f38a | 17 | // printf("Time as a custom formatted string = %s", buffer); |
mbed_official | 0:b3b93997a0a6 | 18 | |
mbed_official | 0:b3b93997a0a6 | 19 | wait(1); |
sandrojuca | 1:62dbcc01f38a | 20 | led =! led; |
mbed_official | 0:b3b93997a0a6 | 21 | } |
mbed_official | 0:b3b93997a0a6 | 22 | } |