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.
41 #if 0 // for documentation only
43 * Get the current time
45 * Returns the current timestamp as the number of seconds since January 1, 1970
46 * (the UNIX timestamp). The value is based on the current value of the
47 * microcontroller Real-Time Clock (RTC), which can be set using <set_time>.
53 * > time_t seconds = time(NULL);
54 * > printf("It is %d seconds since January 1, 1970\n", seconds);
58 * t - Pointer to a time_t to be set, or NULL if not used
59 * returns - Number of seconds since January 1, 1970 (the UNIX timestamp)
61 time_t time(time_t *t
);
65 * Set the current time
67 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
68 * to the time represented by the number of seconds since January 1, 1970
69 * (the UNIX timestamp).
75 * > set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
79 * t - Number of seconds since January 1, 1970 (the UNIX timestamp)
81 void set_time(time_t t
);
83 #if 0 // for documentation only
85 * Converts a tm structure in to a timestamp
87 * Converts the tm structure in to a timestamp in seconds since January 1, 1970
88 * (the UNIX timestamp). The values of tm_wday and tm_yday of the tm structure
89 * are also updated to their appropriate values.
95 * > // setup time structure for Wed, 28 Oct 2009 11:35:37
97 * > t.tm_sec = 37; // 0-59
98 * > t.tm_min = 35; // 0-59
99 * > t.tm_hour = 11; // 0-23
100 * > t.tm_mday = 28; // 1-31
101 * > t.tm_mon = 9; // 0-11
102 * > t.tm_year = 109; // year since 1900
104 * > // convert to timestamp and display (1256729737)
105 * > time_t seconds = mktime(&t);
106 * > printf("Time as seconds since January 1, 1970 = %d\n", seconds);
110 * t - The tm structure to convert
111 * returns - The converted timestamp
113 time_t mktime(struct tm
*t
);
116 #if 0 // for documentation only
117 /* Function: localtime
118 * Converts a timestamp in to a tm structure
120 * Converts the timestamp pointed to by t to a (statically allocated)
124 * > #include "mbed.h"
127 * > time_t seconds = 1256729737;
128 * > struct tm *t = localtime(&seconds);
132 * t - Pointer to the timestamp
133 * returns - Pointer to the (statically allocated) tm structure
135 struct tm
*localtime(const time_t *t
);
138 #if 0 // for documentation only
140 * Converts a timestamp to a human-readable string
142 * Converts a time_t timestamp in seconds since January 1, 1970 (the UNIX
143 * timestamp) to a human readable string format. The result is of the
144 * format: "Wed Oct 28 11:35:37 2009\n"
147 * > #include "mbed.h"
150 * > time_t seconds = time(NULL);
151 * > printf("Time as a string = %s", ctime(&seconds));
155 * t - The timestamp to convert
156 * returns - Pointer to a (statically allocated) string containing the
157 * human readable representation, including a '\n' character
159 char *ctime(const time_t *t
);
162 #if 0 // for documentation only
163 /* Function: strftime
164 * Converts a tm structure to a custom format human-readable string
166 * Creates a formated string from a tm structure, based on a string format
167 * specifier provided.
170 * %S - Second (00-59)
171 * %M - Minute (00-59)
175 * %Y/%y - Year (2009/09)
177 * %A/%a - Weekday Name (Monday/Mon)
178 * %B/%b - Month Name (January/Jan)
179 * %I - 12 Hour Format (01-12)
181 * %X - Time (14:55:02)
182 * %x - Date (08/23/01)
185 * > #include "mbed.h"
188 * > time_t seconds = time(NULL);
191 * > strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
192 * > printf("Time as a formatted string = %s", buffer);
196 * buffer - String buffer to store the result
197 * max - Maximum number of characters to store in the buffer
198 * format - Format specifier string
199 * t - Pointer to the tm structure to convert
200 * returns - Number of characters copied
202 size_t strftime(char *buffer
, size_t max
, const char *format
, const struct tm
*t
);