Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed by
rtc_time.h
00001 /** Implementation of the C time.h functions 00002 * 00003 * Provides mechanisms to set and read the current time, based 00004 * on the microcontroller Real-Time Clock (RTC), plus some 00005 * standard C manipulation and formating functions. 00006 * 00007 * Example: 00008 * @code 00009 * #include "mbed.h" 00010 * 00011 * int main() { 00012 * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 00013 * 00014 * while(1) { 00015 * time_t seconds = time(NULL); 00016 * 00017 * printf("Time as seconds since January 1, 1970 = %d\n", seconds); 00018 * 00019 * printf("Time as a basic string = %s", ctime(&seconds)); 00020 * 00021 * char buffer[32]; 00022 * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); 00023 * printf("Time as a custom formatted string = %s", buffer); 00024 * 00025 * wait(1); 00026 * } 00027 * } 00028 * @endcode 00029 */ 00030 00031 /* mbed Microcontroller Library - rtc_time 00032 * Copyright (c) 2009 ARM Limited. All rights reserved. 00033 */ 00034 00035 #include <time.h> 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 #if 0 // for documentation only 00042 /** Get the current time 00043 * 00044 * Returns the current timestamp as the number of seconds since January 1, 1970 00045 * (the UNIX timestamp). The value is based on the current value of the 00046 * microcontroller Real-Time Clock (RTC), which can be set using <set_time>. 00047 * 00048 * @param t Pointer to a time_t to be set, or NULL if not used 00049 * 00050 * @returns 00051 * Number of seconds since January 1, 1970 (the UNIX timestamp) 00052 * 00053 * Example: 00054 * @code 00055 * #include "mbed.h" 00056 * 00057 * int main() { 00058 * time_t seconds = time(NULL); 00059 * printf("It is %d seconds since January 1, 1970\n", seconds); 00060 * } 00061 * @endcode 00062 */ 00063 time_t time(time_t *t); 00064 #endif 00065 00066 /** Set the current time 00067 * 00068 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) 00069 * to the time represented by the number of seconds since January 1, 1970 00070 * (the UNIX timestamp). 00071 * 00072 * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) 00073 * 00074 * Example: 00075 * @code 00076 * #include "mbed.h" 00077 * 00078 * int main() { 00079 * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 00080 * } 00081 * @endcode 00082 */ 00083 void set_time(time_t t); 00084 00085 #if 0 // for documentation only 00086 /** Converts the tm structure in to a timestamp in seconds since January 1, 1970 00087 * (the UNIX timestamp). The values of tm_wday and tm_yday of the tm structure 00088 * are also updated to their appropriate values. 00089 * 00090 * @param t The tm structure to convert 00091 * 00092 * @returns 00093 * The converted timestamp 00094 * 00095 * Example: 00096 * @code 00097 * #include "mbed.h" 00098 * 00099 * int main() { 00100 * // setup time structure for Wed, 28 Oct 2009 11:35:37 00101 * struct tm t; 00102 * t.tm_sec = 37; // 0-59 00103 * t.tm_min = 35; // 0-59 00104 * t.tm_hour = 11; // 0-23 00105 * t.tm_mday = 28; // 1-31 00106 * t.tm_mon = 9; // 0-11 00107 * t.tm_year = 109; // year since 1900 00108 * 00109 * // convert to timestamp and display (1256729737) 00110 * time_t seconds = mktime(&t); 00111 * printf("Time as seconds since January 1, 1970 = %d\n", seconds); 00112 * } 00113 * @endcode 00114 */ 00115 time_t mktime(struct tm *t); 00116 #endif 00117 00118 #if 0 // for documentation only 00119 /** Converts the timestamp pointed to by t to a (statically allocated) 00120 * tm structure. 00121 * 00122 * @param t Pointer to the timestamp 00123 * 00124 * @returns 00125 * Pointer to the (statically allocated) tm structure 00126 * 00127 * Example: 00128 * @code 00129 * #include "mbed.h" 00130 * 00131 * int main() { 00132 * time_t seconds = 1256729737; 00133 * struct tm *t = localtime(&seconds); 00134 * } 00135 * @endcode 00136 */ 00137 struct tm *localtime(const time_t *t); 00138 #endif 00139 00140 #if 0 // for documentation only 00141 /** Converts a timestamp to a human-readable string 00142 * 00143 * Converts a time_t timestamp in seconds since January 1, 1970 (the UNIX 00144 * timestamp) to a human readable string format. The result is of the 00145 * format: "Wed Oct 28 11:35:37 2009\n" 00146 * 00147 * Example: 00148 * @code 00149 * #include "mbed.h" 00150 * 00151 * int main() { 00152 * time_t seconds = time(NULL); 00153 * printf("Time as a string = %s", ctime(&seconds)); 00154 * } 00155 * @endcode 00156 * 00157 * @param t The timestamp to convert 00158 * 00159 * @returns Pointer to a (statically allocated) string containing the 00160 * human readable representation, including a '\n' character 00161 */ 00162 char *ctime(const time_t *t); 00163 #endif 00164 00165 #if 0 // for documentation only 00166 /** Converts a tm structure to a custom format human-readable string 00167 * 00168 * Creates a formated string from a tm structure, based on a string format 00169 * specifier provided. 00170 * 00171 * Format Specifiers: 00172 * - %S - Second (00-59) 00173 * - %M - Minute (00-59) 00174 * - %H - Hour (00-23) 00175 * - %d - Day (01-31) 00176 * - %m - Month (01-12) 00177 * - %Y/%y - Year (2009/09) 00178 * - %A/%a - Weekday Name (Monday/Mon) 00179 * - %B/%b - Month Name (January/Jan) 00180 * - %I - 12 Hour Format (01-12) 00181 * - %p - "AM" or "PM" 00182 * - %X - Time (14:55:02) 00183 * - %x - Date (08/23/01) 00184 * 00185 * @param buffer String buffer to store the result 00186 * @param max Maximum number of characters to store in the buffer 00187 * @param format Format specifier string 00188 * @param t Pointer to the tm structure to convert 00189 * 00190 * @returns 00191 * Number of characters copied 00192 * 00193 * Example: 00194 * @code 00195 * #include "mbed.h" 00196 * 00197 * int main() { 00198 * time_t seconds = time(NULL); 00199 * 00200 * char buffer[32]; 00201 * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); 00202 * printf("Time as a formatted string = %s", buffer); 00203 * } 00204 * @endcode 00205 */ 00206 size_t strftime(char *buffer, size_t max, const char *format, const struct tm *t); 00207 #endif 00208 00209 #ifdef __cplusplus 00210 } 00211 #endif
Generated on Tue Jul 12 2022 20:12:25 by
1.7.2