2 * Implementation of the C time.h functions
4 * Provides mechanisms to set and read the current time, based
5 * on the microcontroller Real-Time Clock (RTC), plus some
6 * standard C manipulation and formating functions.
12 * > set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
15 * > time_t seconds = time(NULL);
17 * > printf("Time as seconds since January 1, 1970 = %d\n", seconds);
19 * > printf("Time as a basic string = %s", ctime(&seconds));
22 * > strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
23 * > printf("Time as a custom formatted string = %s", buffer);
30 /* mbed Microcontroller Library - rtc_time
31 * Copyright (c) 2009 ARM Limited. All rights reserved.
40 #if 0 // for documentation only
42 * Get the current time
44 * Returns the current timestamp as the number of seconds since January 1, 1970
45 * (the UNIX timestamp). The value is based on the current value of the
46 * microcontroller Real-Time Clock (RTC), which can be set using <set_time>.
52 * > time_t seconds = time(NULL);
53 * > printf("It is %d seconds since January 1, 1970\n", seconds);
57 * t - Pointer to a time_t to be set, or NULL if not used
58 * returns - Number of seconds since January 1, 1970 (the UNIX timestamp)
60 time_t time(time_t *t
);
64 * Set the current time
66 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
67 * to the time represented by the number of seconds since January 1, 1970
68 * (the UNIX timestamp).
74 * > set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
78 * t - Number of seconds since January 1, 1970 (the UNIX timestamp)
80 void set_time(time_t t
);
82 #if 0 // for documentation only
84 * Converts a tm structure in to a timestamp
86 * Converts the tm structure in to a timestamp in seconds since January 1, 1970
87 * (the UNIX timestamp). The values of tm_wday and tm_yday of the tm structure
88 * are also updated to their appropriate values.
94 * > // setup time structure for Wed, 28 Oct 2009 11:35:37
96 * > t.tm_sec = 37; // 0-59
97 * > t.tm_min = 35; // 0-59
98 * > t.tm_hour = 11; // 0-23
99 * > t.tm_mday = 28; // 1-31
100 * > t.tm_mon = 9; // 0-11
101 * > t.tm_year = 109; // year since 1900
103 * > // convert to timestamp and display (1256729737)
104 * > time_t seconds = mktime(&t);
105 * > printf("Time as seconds since January 1, 1970 = %d\n", seconds);
109 * t - The tm structure to convert
110 * returns - The converted timestamp
112 time_t mktime(struct tm
*t
);
115 #if 0 // for documentation only
116 /* Function: localtime
117 * Converts a timestamp in to a tm structure
119 * Converts the timestamp pointed to by t to a (statically allocated)
123 * > #include "mbed.h"
126 * > time_t seconds = 1256729737;
127 * > struct tm *t = localtime(&seconds);
131 * t - Pointer to the timestamp
132 * returns - Pointer to the (statically allocated) tm structure
134 struct tm
*localtime(const time_t *t
);
137 #if 0 // for documentation only
139 * Converts a timestamp to a human-readable string
141 * Converts a time_t timestamp in seconds since January 1, 1970 (the UNIX
142 * timestamp) to a human readable string format. The result is of the
143 * format: "Wed Oct 28 11:35:37 2009\n"
146 * > #include "mbed.h"
149 * > time_t seconds = time(NULL);
150 * > printf("Time as a string = %s", ctime(&seconds));
154 * t - The timestamp to convert
155 * returns - Pointer to a (statically allocated) string containing the
156 * human readable representation, including a '\n' character
158 char *ctime(const time_t *t
);
161 #if 0 // for documentation only
162 /* Function: strftime
163 * Converts a tm structure to a custom format human-readable string
165 * Creates a formated string from a tm structure, based on a string format
166 * specifier provided.
169 * %S - Second (00-59)
170 * %M - Minute (00-59)
174 * %Y/%y - Year (2009/09)
176 * %A/%a - Weekday Name (Monday/Mon)
177 * %B/%b - Month Name (January/Jan)
178 * %I - 12 Hour Format (01-12)
180 * %X - Time (14:55:02)
181 * %x - Date (08/23/01)
184 * > #include "mbed.h"
187 * > time_t seconds = time(NULL);
190 * > strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
191 * > printf("Time as a formatted string = %s", buffer);
195 * buffer - String buffer to store the result
196 * max - Maximum number of characters to store in the buffer
197 * format - Format specifier string
198 * t - Pointer to the tm structure to convert
199 * returns - Number of characters copied
201 size_t strftime(char *buffer
, size_t max
, const char *format
, const struct tm
*t
);