sl@0
|
1 |
/** @file ../include/time.h
|
sl@0
|
2 |
@internalComponent
|
sl@0
|
3 |
*/
|
sl@0
|
4 |
|
sl@0
|
5 |
/** @fn asctime(const struct tm *tm)
|
sl@0
|
6 |
@param tm
|
sl@0
|
7 |
|
sl@0
|
8 |
Refer to ctime() for the documentation
|
sl@0
|
9 |
@see gettimeofday()
|
sl@0
|
10 |
@see getenv()
|
sl@0
|
11 |
@see time()
|
sl@0
|
12 |
@see tzset()
|
sl@0
|
13 |
|
sl@0
|
14 |
|
sl@0
|
15 |
|
sl@0
|
16 |
|
sl@0
|
17 |
@publishedAll
|
sl@0
|
18 |
@externallyDefinedApi
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
/** @fn clock(void)
|
sl@0
|
22 |
@return clock is just for build support and hence returns 0.
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
The clock function
|
sl@0
|
28 |
determines the amount of processor time used since the invocation of the
|
sl@0
|
29 |
calling process, measured in CLOCKS_PER_SEC s of a second.
|
sl@0
|
30 |
|
sl@0
|
31 |
Note: the clock system call eventually calls Symbian OS call user::GetCpuTime(),
|
sl@0
|
32 |
which is not supported from version 8.0b, hence this api is included for build
|
sl@0
|
33 |
support only.
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
|
sl@0
|
37 |
@publishedAll
|
sl@0
|
38 |
@externallyDefinedApi
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
|
sl@0
|
41 |
/** @fn ctime(const time_t *clock)
|
sl@0
|
42 |
@param clock
|
sl@0
|
43 |
|
sl@0
|
44 |
Note: This description also covers the following functions -
|
sl@0
|
45 |
difftime() asctime() localtime() gmtime() mktime() ctime_r() localtime_r() gmtime_r() asctime_r()
|
sl@0
|
46 |
|
sl@0
|
47 |
@return Each of these functions returns the value described, NULL, or -1 in the case of mktime if an error was detected.
|
sl@0
|
48 |
|
sl@0
|
49 |
The functions ctime, gmtime and localtime all take as an argument a time value representing the time
|
sl@0
|
50 |
in seconds since the Epoch (00:00:00 UTC, January 1, 1970); see time
|
sl@0
|
51 |
|
sl@0
|
52 |
The function localtime converts the time value pointed at by clock and returns a pointer to a " struct tm " (described below) which contains the broken down time information
|
sl@0
|
53 |
for the value after adjusting for the current time zone (and any other factors
|
sl@0
|
54 |
such as Daylight Saving Time). Time zone adjustments are performed as specified
|
sl@0
|
55 |
by the TZ environment variable (see the tzset function). localtime uses tzset to initialize time conversion information
|
sl@0
|
56 |
if tzset has not already been called by the process.
|
sl@0
|
57 |
|
sl@0
|
58 |
After filling in the tm structure, localtime sets the tm_isdst's Nth element of tzname to a pointer to a ASCII string that is the time zone abbreviation to be
|
sl@0
|
59 |
used with localtime's (return, value.);
|
sl@0
|
60 |
|
sl@0
|
61 |
The function gmtime similarly converts the time value without any time zone adjustment
|
sl@0
|
62 |
and returns a pointer to a tm structure (described below).
|
sl@0
|
63 |
|
sl@0
|
64 |
The ctime function adjusts the time value for the current time zone, in
|
sl@0
|
65 |
the same manner as localtime, and returns a pointer to a 26-character string of the form: Thu Nov 24 18:22:48 1986
|
sl@0
|
66 |
\\0
|
sl@0
|
67 |
|
sl@0
|
68 |
All the fields have constant width.
|
sl@0
|
69 |
|
sl@0
|
70 |
The ctime_r function provides the same functionality as ctime except the caller must provide the output buffer buf to store the result, which must be at least 26 characters long.
|
sl@0
|
71 |
|
sl@0
|
72 |
The localtime_r and gmtime_r functions provide the same functionality as localtime and gmtime respectively, except the caller must provide the output buffer result.
|
sl@0
|
73 |
|
sl@0
|
74 |
The asctime function
|
sl@0
|
75 |
converts the broken down time in the structure tm pointed at by *tm to the form
|
sl@0
|
76 |
shown in the example above.
|
sl@0
|
77 |
|
sl@0
|
78 |
The asctime_r function provides the same functionality as asctime except the caller provides the output buffer buf to store the result, which must be at least 26 characters long.
|
sl@0
|
79 |
|
sl@0
|
80 |
The functions mktime converts the broken-down time in the structure pointed to by
|
sl@0
|
81 |
tm into a time value with the same encoding as that of the values returned by
|
sl@0
|
82 |
the time function (that is, seconds from the Epoch, UTC). The mktime function interprets the input structure according to the current
|
sl@0
|
83 |
timezone setting (see tzset ).
|
sl@0
|
84 |
|
sl@0
|
85 |
The original values of the tm_wday and tm_yday components of the structure are ignored, and the original values
|
sl@0
|
86 |
of the other components are not restricted to their normal ranges and will be
|
sl@0
|
87 |
normalized if needed. For example, October 40 is changed into November 9, a tm_hour of -1 means 1 hour before midnight, tm_mday of 0 means the day preceding the current month, and tm_mon of -2 means 2 months before January of tm_year.
|
sl@0
|
88 |
|
sl@0
|
89 |
A positive or zero value for tm_isdst causes mktime to presume initially that summer time (for example, Daylight
|
sl@0
|
90 |
Saving Time) is or is not in effect for the specified time.. A negative value
|
sl@0
|
91 |
for tm_isdst causes the mktime function to attempt to define whether summer time is in effect
|
sl@0
|
92 |
for the specified time. The tm_isdst and tm_gmtoff members are forced to zero by timegm.
|
sl@0
|
93 |
|
sl@0
|
94 |
On successful completion, the values of the tm_wday and tm_yday components of the structure are set appropriately and the other
|
sl@0
|
95 |
components are set to represent the specified calendar time, but with their
|
sl@0
|
96 |
values forced to their normal ranges: The final value of tm_mday is not set until tm_mon and tm_year are determined.
|
sl@0
|
97 |
|
sl@0
|
98 |
The mktime function returns the specified calendar time. If the calendar
|
sl@0
|
99 |
time cannot be represented, it returns -1.
|
sl@0
|
100 |
|
sl@0
|
101 |
The difftime function
|
sl@0
|
102 |
returns the difference between two calendar times, ( time1 - time0), expressed in seconds.
|
sl@0
|
103 |
|
sl@0
|
104 |
External declarations as well as the tm structure definition are in the
|
sl@0
|
105 |
@code
|
sl@0
|
106 |
#include <time.h> include file. The tm structure includes
|
sl@0
|
107 |
@endcode
|
sl@0
|
108 |
at least the following fields:
|
sl@0
|
109 |
|
sl@0
|
110 |
@code
|
sl@0
|
111 |
|
sl@0
|
112 |
int tm_sec; // seconds (0 - 60)
|
sl@0
|
113 |
int tm_min; // minutes (0 - 59)
|
sl@0
|
114 |
int tm_hour; // hours (0 - 23)
|
sl@0
|
115 |
int tm_mday; // day of month (1 - 31)
|
sl@0
|
116 |
int tm_mon; // month of year (0 - 11)
|
sl@0
|
117 |
int tm_year; // year - 1900
|
sl@0
|
118 |
int tm_wday; // day of week (Sunday = 0)
|
sl@0
|
119 |
int tm_yday; // day of year (0 - 365)
|
sl@0
|
120 |
int tm_isdst; // is summer time in effect?
|
sl@0
|
121 |
char *tm_zone; // abbreviation of timezone name
|
sl@0
|
122 |
long tm_gmtoff; // offset from UTC in seconds
|
sl@0
|
123 |
|
sl@0
|
124 |
@endcode
|
sl@0
|
125 |
|
sl@0
|
126 |
The
|
sl@0
|
127 |
field tm_isdst is non-zero if summer time is in effect.
|
sl@0
|
128 |
|
sl@0
|
129 |
The field tm_gmtoff is the offset (in seconds) of the time represented from UTC, with positive
|
sl@0
|
130 |
values indicating east of the Prime Meridian.
|
sl@0
|
131 |
|
sl@0
|
132 |
Examples:
|
sl@0
|
133 |
@code
|
sl@0
|
134 |
//Example usage of asctime,localtime and gmtime:
|
sl@0
|
135 |
#include <time.h>
|
sl@0
|
136 |
#include <stdio.h>
|
sl@0
|
137 |
int main(){
|
sl@0
|
138 |
time_t t;
|
sl@0
|
139 |
struct tm *timeptr;
|
sl@0
|
140 |
char* asc_time;
|
sl@0
|
141 |
t = time (NULL); //Get current time in seconds from Epoc
|
sl@0
|
142 |
//Fill tm struct w.r.t localtime using localtime
|
sl@0
|
143 |
timeptr = localtime (&t;);
|
sl@0
|
144 |
//Use this to convert it to a string indicating time w.r.t localtime
|
sl@0
|
145 |
asc_time = asctime (timeptr);
|
sl@0
|
146 |
printf ("Time from asctime w.r.t localtime : %s", asc_time);
|
sl@0
|
147 |
//Fill tm struct w.r.t GMT using gmtime
|
sl@0
|
148 |
timeptr = gmtime (&t;);
|
sl@0
|
149 |
//Use this to convert it to a string indicating time w.r.t GMT
|
sl@0
|
150 |
asc_time = asctime (timeptr);
|
sl@0
|
151 |
printf ("Time from asctime w.r.t gmtime : %s", asc_time);
|
sl@0
|
152 |
return 0;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
@endcode
|
sl@0
|
156 |
Output
|
sl@0
|
157 |
@code
|
sl@0
|
158 |
Time from asctime w.r.t localtime : Thu Jun 22 10:42:27 2006
|
sl@0
|
159 |
Time from asctime w.r.t gmtime : Thu Jun 22 05:12:27 2006
|
sl@0
|
160 |
|
sl@0
|
161 |
@endcode
|
sl@0
|
162 |
@code
|
sl@0
|
163 |
//Example usage of ctime,mktime:
|
sl@0
|
164 |
#include <time.h>
|
sl@0
|
165 |
#include <stdio.h>
|
sl@0
|
166 |
int main(){
|
sl@0
|
167 |
time_t t;
|
sl@0
|
168 |
struct tm timeptr;
|
sl@0
|
169 |
char* c_time;
|
sl@0
|
170 |
//Fill the tm struct with values
|
sl@0
|
171 |
timeptr.tm_year = 2001;
|
sl@0
|
172 |
timeptr.tm_mon = 6;
|
sl@0
|
173 |
timeptr.tm_mday = 4;
|
sl@0
|
174 |
timeptr.tm_hour = 0;
|
sl@0
|
175 |
timeptr.tm_min = 0;
|
sl@0
|
176 |
timeptr.tm_sec = 1;
|
sl@0
|
177 |
timeptr.tm_isdst = -1;
|
sl@0
|
178 |
t = mktime (&timeptr;); //Call mktime to make time in seconds w.r.t epoc
|
sl@0
|
179 |
//Convert this to a string indicating time using ctime
|
sl@0
|
180 |
c_time = ctime (&t;);
|
sl@0
|
181 |
printf ("Time from ctime : %s", c_time);
|
sl@0
|
182 |
return 0;
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
@endcode
|
sl@0
|
186 |
Output
|
sl@0
|
187 |
@code
|
sl@0
|
188 |
Time from ctime : Thu Jan 1 05:29:59 1970
|
sl@0
|
189 |
|
sl@0
|
190 |
@endcode
|
sl@0
|
191 |
@code
|
sl@0
|
192 |
//Example usage of difftime:
|
sl@0
|
193 |
#include <time.h>
|
sl@0
|
194 |
#include <unistd.h>
|
sl@0
|
195 |
#include <stdio.h>
|
sl@0
|
196 |
int main(){
|
sl@0
|
197 |
time_t t0,t1,t2;
|
sl@0
|
198 |
//Set initial and final values
|
sl@0
|
199 |
t0 = 10;
|
sl@0
|
200 |
t1 = 20;
|
sl@0
|
201 |
t2 = difftime (t1, t0); //Find the time difference using difftime
|
sl@0
|
202 |
printf ("Result of difftime = %d", t2);
|
sl@0
|
203 |
return 0;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
@endcode
|
sl@0
|
207 |
Output
|
sl@0
|
208 |
@code
|
sl@0
|
209 |
Result of difftime = 10
|
sl@0
|
210 |
|
sl@0
|
211 |
@endcode
|
sl@0
|
212 |
@see gettimeofday()
|
sl@0
|
213 |
@see getenv()
|
sl@0
|
214 |
@see time()
|
sl@0
|
215 |
@see tzset()
|
sl@0
|
216 |
|
sl@0
|
217 |
|
sl@0
|
218 |
Bugs:
|
sl@0
|
219 |
|
sl@0
|
220 |
Except for difftime, mktime, and the _r variants of the other functions,
|
sl@0
|
221 |
these functions leaves their result in an internal static object and return
|
sl@0
|
222 |
a pointer to that object.
|
sl@0
|
223 |
Subsequent calls to these
|
sl@0
|
224 |
function will modify the same object.
|
sl@0
|
225 |
|
sl@0
|
226 |
The C Standard provides no mechanism for a program to modify its current
|
sl@0
|
227 |
local timezone setting, and the POSIX -standard method is not reentrant.
|
sl@0
|
228 |
(However, thread-safe implementations are provided
|
sl@0
|
229 |
in the POSIX threaded environment.)
|
sl@0
|
230 |
|
sl@0
|
231 |
The tm_zone field of a returned tm
|
sl@0
|
232 |
structure points to a static array of characters,
|
sl@0
|
233 |
which will also be overwritten by any subsequent calls (as well as by
|
sl@0
|
234 |
subsequent call to tzset )
|
sl@0
|
235 |
|
sl@0
|
236 |
|
sl@0
|
237 |
@publishedAll
|
sl@0
|
238 |
@externallyDefinedApi
|
sl@0
|
239 |
*/
|
sl@0
|
240 |
|
sl@0
|
241 |
/** @fn difftime(time_t time1, time_t time0)
|
sl@0
|
242 |
@param time1
|
sl@0
|
243 |
@param time0
|
sl@0
|
244 |
|
sl@0
|
245 |
Refer to ctime() for the documentation
|
sl@0
|
246 |
@see gettimeofday()
|
sl@0
|
247 |
@see getenv()
|
sl@0
|
248 |
@see time()
|
sl@0
|
249 |
@see tzset()
|
sl@0
|
250 |
|
sl@0
|
251 |
|
sl@0
|
252 |
|
sl@0
|
253 |
|
sl@0
|
254 |
@publishedAll
|
sl@0
|
255 |
@externallyDefinedApi
|
sl@0
|
256 |
*/
|
sl@0
|
257 |
|
sl@0
|
258 |
/** @fn gmtime(const time_t *clock)
|
sl@0
|
259 |
@param clock
|
sl@0
|
260 |
|
sl@0
|
261 |
Refer to ctime() for the documentation
|
sl@0
|
262 |
@see gettimeofday()
|
sl@0
|
263 |
@see getenv()
|
sl@0
|
264 |
@see time()
|
sl@0
|
265 |
@see tzset()
|
sl@0
|
266 |
|
sl@0
|
267 |
|
sl@0
|
268 |
|
sl@0
|
269 |
|
sl@0
|
270 |
@publishedAll
|
sl@0
|
271 |
@externallyDefinedApi
|
sl@0
|
272 |
*/
|
sl@0
|
273 |
|
sl@0
|
274 |
/** @fn localtime(const time_t *clock)
|
sl@0
|
275 |
@param clock
|
sl@0
|
276 |
|
sl@0
|
277 |
Refer to ctime() for the documentation
|
sl@0
|
278 |
@see gettimeofday()
|
sl@0
|
279 |
@see getenv()
|
sl@0
|
280 |
@see time()
|
sl@0
|
281 |
@see tzset()
|
sl@0
|
282 |
|
sl@0
|
283 |
|
sl@0
|
284 |
The localtime() is not guaranteed to be thread safe.
|
sl@0
|
285 |
|
sl@0
|
286 |
@publishedAll
|
sl@0
|
287 |
@externallyDefinedApi
|
sl@0
|
288 |
*/
|
sl@0
|
289 |
|
sl@0
|
290 |
/** @fn mktime(struct tm *tm)
|
sl@0
|
291 |
@param tm
|
sl@0
|
292 |
|
sl@0
|
293 |
Refer to ctime() for the documentation
|
sl@0
|
294 |
@see gettimeofday()
|
sl@0
|
295 |
@see getenv()
|
sl@0
|
296 |
@see time()
|
sl@0
|
297 |
@see tzset()
|
sl@0
|
298 |
|
sl@0
|
299 |
|
sl@0
|
300 |
|
sl@0
|
301 |
|
sl@0
|
302 |
@publishedAll
|
sl@0
|
303 |
@externallyDefinedApi
|
sl@0
|
304 |
*/
|
sl@0
|
305 |
|
sl@0
|
306 |
/** @fn strftime(char * s, size_t maxsize, const char * format, const struct tm * t)
|
sl@0
|
307 |
@param s
|
sl@0
|
308 |
@param maxsize
|
sl@0
|
309 |
@param format
|
sl@0
|
310 |
@param t
|
sl@0
|
311 |
|
sl@0
|
312 |
The strftime function formats the information from t into the buffer s according to the string pointed to by format .
|
sl@0
|
313 |
The format string consists of zero or more conversion specifications and
|
sl@0
|
314 |
ordinary characters.
|
sl@0
|
315 |
All ordinary characters are copied directly into the buffer.
|
sl@0
|
316 |
A conversion specification consists of a percent sign "\%"
|
sl@0
|
317 |
and one other character.
|
sl@0
|
318 |
|
sl@0
|
319 |
No more than maxsize characters will be placed into the array. If the total number of resulting characters, including the terminating NULL character, is not more
|
sl@0
|
320 |
than maxsize , strftime returns the number of characters in the array, not counting
|
sl@0
|
321 |
the terminating NULL. Otherwise, zero is returned and the buffer contents are
|
sl@0
|
322 |
indeterminate.
|
sl@0
|
323 |
|
sl@0
|
324 |
@code
|
sl@0
|
325 |
The conversion specifications are copied to the buffer after expansion as follows:-
|
sl@0
|
326 |
%A is replaced by national representation of the full weekday name.
|
sl@0
|
327 |
%a is replaced by national representation of the abbreviated weekday name.
|
sl@0
|
328 |
%B is replaced by national representation of the full month name.
|
sl@0
|
329 |
%b is replaced by national representation of the abbreviated month name.
|
sl@0
|
330 |
%C is replaced by (year / 100) as decimal number; single digits are preceded by a zero.
|
sl@0
|
331 |
%c is replaced by national representation of time and date.
|
sl@0
|
332 |
%D is equivalent to "%m/%d/%y".
|
sl@0
|
333 |
%d is replaced by the day of the month as a decimal number (01-31).
|
sl@0
|
334 |
%E* %O*
|
sl@0
|
335 |
POSIX locale extensions. The sequences %Ec %EC %Ex %EX %Ey %EY %Od %Oe %OH %OI %Om %OM %OS %Ou %OU %OV %Ow %OW %Oy are supposed to provide alternate representations.
|
sl@0
|
336 |
Additionally %OB implemented to represent alternative months names (used standalone, without day mentioned).
|
sl@0
|
337 |
|
sl@0
|
338 |
%e is replaced by the day of month as a decimal number (1-31); single digits are preceded by a blank.
|
sl@0
|
339 |
%F is equivalent to "%Y-%m-%d".
|
sl@0
|
340 |
%G is replaced by a year as a decimal number with century. This year is the one that contains the greater part of the week (Monday as the first day of the week).
|
sl@0
|
341 |
%g is replaced by the same year as in "%G", but as a decimal number without century (00-99).
|
sl@0
|
342 |
%H is replaced by the hour (24-hour clock) as a decimal number (00-23).
|
sl@0
|
343 |
%h the same as %b.
|
sl@0
|
344 |
%I is replaced by the hour (12-hour clock) as a decimal number (01-12).
|
sl@0
|
345 |
%j is replaced by the day of the year as a decimal number (001-366).
|
sl@0
|
346 |
%k is replaced by the hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a blank.
|
sl@0
|
347 |
%l is replaced by the hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a blank.
|
sl@0
|
348 |
%M is replaced by the minute as a decimal number (00-59).
|
sl@0
|
349 |
%m is replaced by the month as a decimal number (01-12).
|
sl@0
|
350 |
%n is replaced by a newline.
|
sl@0
|
351 |
%O* the same as %E*.
|
sl@0
|
352 |
%p is replaced by national representation of either "ante meridiem" or "post meridiem" as appropriate.
|
sl@0
|
353 |
%R is equivalent to "%H:%M".
|
sl@0
|
354 |
%r is equivalent to "%I:%M:%S %p".
|
sl@0
|
355 |
%S is replaced by the second as a decimal number (00-60).
|
sl@0
|
356 |
%s is replaced by the number of seconds since the Epoch, UTC (see mktime).
|
sl@0
|
357 |
%T is equivalent to "%H:%M:%S".
|
sl@0
|
358 |
%t is replaced by a tab.
|
sl@0
|
359 |
%U is replaced by the week number of the year (Sunday as the first day of the week) as a decimal number (00-53).
|
sl@0
|
360 |
%u is replaced by the weekday (Monday as the first day of the week) as a decimal number (1-7).
|
sl@0
|
361 |
%V is replaced by the week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it is week 1; otherwise it is the last week of the previous year, and the next week is week 1.
|
sl@0
|
362 |
%v is equivalent to "%e-%b-%Y".
|
sl@0
|
363 |
%W is replaced by the week number of the year (Monday as the first day of the week) as a decimal number (00-53).
|
sl@0
|
364 |
%w is replaced by the weekday (Sunday as the first day of the week) as a decimal number (0-6).
|
sl@0
|
365 |
%X is replaced by national representation of the time.
|
sl@0
|
366 |
%x is replaced by national representation of the date.
|
sl@0
|
367 |
%Y is replaced by the year with century as a decimal number.
|
sl@0
|
368 |
%y is replaced by the year without century as a decimal number (00-99).
|
sl@0
|
369 |
%Z is replaced by the time zone name.
|
sl@0
|
370 |
%z is replaced by the time zone offset from UTC; a leading plus sign stands for east of UTC, a minus sign for west of UTC, hours and minutes follow with two digits each and no delimiter between them (common form for RFC 822 date headers).
|
sl@0
|
371 |
%+ is replaced by national representation of the date and time (the format is similar to that produced by 'date( )' function ).
|
sl@0
|
372 |
%-* GNU libc extension. Do not do any padding when performing numerical outputs.
|
sl@0
|
373 |
%_* GNU libc extension. Explicitly specify space for padding.
|
sl@0
|
374 |
%0* GNU libc extension. Explicitly specify zero for padding.
|
sl@0
|
375 |
%% is replaced by ‘%’.
|
sl@0
|
376 |
@endcode
|
sl@0
|
377 |
|
sl@0
|
378 |
Examples:
|
sl@0
|
379 |
@code
|
sl@0
|
380 |
#include <string.h>
|
sl@0
|
381 |
#include <stdio.h>
|
sl@0
|
382 |
#include <time.h>
|
sl@0
|
383 |
#include <locale.h>
|
sl@0
|
384 |
int main()
|
sl@0
|
385 |
{
|
sl@0
|
386 |
struct tm tm;
|
sl@0
|
387 |
char buf[255];
|
sl@0
|
388 |
char *locale;
|
sl@0
|
389 |
locale = setlocale(LC_TIME,"en_GB.ISO-8859-1");
|
sl@0
|
390 |
if( locale != NULL)
|
sl@0
|
391 |
{
|
sl@0
|
392 |
strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm;);
|
sl@0
|
393 |
printf("sec = %d min = %d hours = %d
|
sl@0
|
394 |
Year = %d Month = %d day = %d
|
sl@0
|
395 |
",\
|
sl@0
|
396 |
tm.tm_sec,tm.tm_min,tm.tm_hour,tm.tm_year,tm.tm_mon,tm.tm_mday);
|
sl@0
|
397 |
strftime(buf, sizeof(buf), "%d %B %Y %H:%M:%S", &tm;);
|
sl@0
|
398 |
puts(buf);
|
sl@0
|
399 |
strptime("Mon","%a", &tm;);
|
sl@0
|
400 |
strftime(buf, sizeof(buf), "%a", &tm;);
|
sl@0
|
401 |
puts(buf);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
else
|
sl@0
|
404 |
printf("Failed to set locale
|
sl@0
|
405 |
");
|
sl@0
|
406 |
}
|
sl@0
|
407 |
|
sl@0
|
408 |
@endcode
|
sl@0
|
409 |
Output
|
sl@0
|
410 |
@code
|
sl@0
|
411 |
sec = 1 min = 31 hours = 18
|
sl@0
|
412 |
Year = 101 Month = 10 day = 12
|
sl@0
|
413 |
12 November 2001 18:31:01
|
sl@0
|
414 |
Mon
|
sl@0
|
415 |
|
sl@0
|
416 |
@endcode
|
sl@0
|
417 |
@see printf()
|
sl@0
|
418 |
@see ctime()
|
sl@0
|
419 |
@see strptime()
|
sl@0
|
420 |
@see wcsftime()
|
sl@0
|
421 |
|
sl@0
|
422 |
|
sl@0
|
423 |
|
sl@0
|
424 |
|
sl@0
|
425 |
@publishedAll
|
sl@0
|
426 |
@externallyDefinedApi
|
sl@0
|
427 |
*/
|
sl@0
|
428 |
|
sl@0
|
429 |
/** @fn time(time_t *p)
|
sl@0
|
430 |
@param p
|
sl@0
|
431 |
@return On success the value of time in seconds since the Epoch is returned. On error
|
sl@0
|
432 |
(time_t)(-1) is returned and errno is set appropriately.
|
sl@0
|
433 |
|
sl@0
|
434 |
The time function returns the value of time in seconds since 0 hours, 0
|
sl@0
|
435 |
minutes, 0 seconds, January 1, 1970, Coordinated Universal Time. If an error occurs, time returns the value ( time_t)(-1) .
|
sl@0
|
436 |
|
sl@0
|
437 |
The return value is also stored in * p ,
|
sl@0
|
438 |
provided that p is non-null.
|
sl@0
|
439 |
|
sl@0
|
440 |
Examples:
|
sl@0
|
441 |
@code
|
sl@0
|
442 |
/*
|
sl@0
|
443 |
* Detailed description : sample usage of time system call
|
sl@0
|
444 |
*/
|
sl@0
|
445 |
#include <time.h>
|
sl@0
|
446 |
int main()
|
sl@0
|
447 |
{
|
sl@0
|
448 |
time_t Time ;
|
sl@0
|
449 |
if(time(&Time;) < 0 )
|
sl@0
|
450 |
{
|
sl@0
|
451 |
printf("Time system call failed
|
sl@0
|
452 |
") ;
|
sl@0
|
453 |
return -1 ;
|
sl@0
|
454 |
}
|
sl@0
|
455 |
printf("Time value is %u
|
sl@0
|
456 |
" , Time) ;
|
sl@0
|
457 |
return 0 ;
|
sl@0
|
458 |
}
|
sl@0
|
459 |
|
sl@0
|
460 |
@endcode
|
sl@0
|
461 |
Output
|
sl@0
|
462 |
@code
|
sl@0
|
463 |
|
sl@0
|
464 |
Time value is 1176916948
|
sl@0
|
465 |
|
sl@0
|
466 |
@endcode
|
sl@0
|
467 |
@see gettimeofday()
|
sl@0
|
468 |
@see ctime()
|
sl@0
|
469 |
|
sl@0
|
470 |
|
sl@0
|
471 |
Bugs:
|
sl@0
|
472 |
|
sl@0
|
473 |
Neither -isoC-99 nor -p1003.1-2001 requires time to set errno on failure; thus, it is impossible for an application to distinguish
|
sl@0
|
474 |
the valid time value -1 (representing the last UTC second of 1969)
|
sl@0
|
475 |
from the error return value.
|
sl@0
|
476 |
|
sl@0
|
477 |
Systems conforming to earlier versions of the C and POSIX standards (including older versions of )
|
sl@0
|
478 |
did not set * p in the error case.
|
sl@0
|
479 |
|
sl@0
|
480 |
|
sl@0
|
481 |
@publishedAll
|
sl@0
|
482 |
@externallyDefinedApi
|
sl@0
|
483 |
*/
|
sl@0
|
484 |
|
sl@0
|
485 |
/** @fn tzset(void)
|
sl@0
|
486 |
|
sl@0
|
487 |
The tzset function
|
sl@0
|
488 |
initializes time conversion information used by the library routine localtime .
|
sl@0
|
489 |
The environment variable TZ specifies how this is done.
|
sl@0
|
490 |
|
sl@0
|
491 |
If TZ does not appear in the environment, the best available approximation
|
sl@0
|
492 |
to local wall clock time is used.
|
sl@0
|
493 |
|
sl@0
|
494 |
If TZ appears in the environment but its value is a null string, Coordinated
|
sl@0
|
495 |
Universal Time ( UTC )
|
sl@0
|
496 |
is used (without leap second correction).
|
sl@0
|
497 |
|
sl@0
|
498 |
|
sl@0
|
499 |
|
sl@0
|
500 |
Examples:
|
sl@0
|
501 |
@code
|
sl@0
|
502 |
#include <time.h>
|
sl@0
|
503 |
#include <stdio.h>
|
sl@0
|
504 |
int main(){
|
sl@0
|
505 |
time_t t;
|
sl@0
|
506 |
char* c_time;
|
sl@0
|
507 |
tzset(); //Call tzset
|
sl@0
|
508 |
c_time = ctime (&t;); //Get time-string using ctime for Epoc time
|
sl@0
|
509 |
printf ("Time from ctime after tzset: %s", c_time);
|
sl@0
|
510 |
return 0;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
|
sl@0
|
513 |
@endcode
|
sl@0
|
514 |
Output
|
sl@0
|
515 |
@code
|
sl@0
|
516 |
Time from ctime after tzset: Sun Apr 7 02:24:08 1974
|
sl@0
|
517 |
|
sl@0
|
518 |
@endcode
|
sl@0
|
519 |
@see gettimeofday()
|
sl@0
|
520 |
@see ctime()
|
sl@0
|
521 |
@see getenv()
|
sl@0
|
522 |
@see time()
|
sl@0
|
523 |
|
sl@0
|
524 |
|
sl@0
|
525 |
@see gettimeofday()
|
sl@0
|
526 |
@see ctime()
|
sl@0
|
527 |
@see getenv()
|
sl@0
|
528 |
@see time()
|
sl@0
|
529 |
@see gettimeofday()
|
sl@0
|
530 |
@see ctime()
|
sl@0
|
531 |
@see getenv()
|
sl@0
|
532 |
@see time()
|
sl@0
|
533 |
|
sl@0
|
534 |
|
sl@0
|
535 |
|
sl@0
|
536 |
|
sl@0
|
537 |
@publishedAll
|
sl@0
|
538 |
@externallyDefinedApi
|
sl@0
|
539 |
*/
|
sl@0
|
540 |
|
sl@0
|
541 |
/** @fn clock_getres(clockid_t clock_id, struct timespec *res)
|
sl@0
|
542 |
@param clock_id
|
sl@0
|
543 |
@param res
|
sl@0
|
544 |
|
sl@0
|
545 |
Refer to clock_gettime() for the documentation
|
sl@0
|
546 |
@see adjtime()
|
sl@0
|
547 |
@see ctime()
|
sl@0
|
548 |
|
sl@0
|
549 |
|
sl@0
|
550 |
|
sl@0
|
551 |
|
sl@0
|
552 |
@publishedAll
|
sl@0
|
553 |
@externallyDefinedApi
|
sl@0
|
554 |
*/
|
sl@0
|
555 |
|
sl@0
|
556 |
/** @fn clock_gettime(clockid_t clock_id, struct timespec *tp)
|
sl@0
|
557 |
@param clock_id
|
sl@0
|
558 |
@param tp
|
sl@0
|
559 |
|
sl@0
|
560 |
Note: This description also covers the following functions -
|
sl@0
|
561 |
clock_settime() clock_getres() clock_getcpuclockid()
|
sl@0
|
562 |
|
sl@0
|
563 |
@return All the above APIs return 0 on success and -1 on failure.
|
sl@0
|
564 |
|
sl@0
|
565 |
@code
|
sl@0
|
566 |
#include < sys/time.h > as:
|
sl@0
|
567 |
@endcode
|
sl@0
|
568 |
The clock_gettime and clock_settime allow the calling process to retrieve or set the value used by a clock
|
sl@0
|
569 |
which is specified by clock_id.
|
sl@0
|
570 |
|
sl@0
|
571 |
The clock_id argument can be one of four values: CLOCK_REALTIME for time
|
sl@0
|
572 |
that increments as a wall clock should, CLOCK_MONOTONIC which increments in
|
sl@0
|
573 |
SI seconds, CLOCK_VIRTUAL for time that increments only when the CPU is running
|
sl@0
|
574 |
in user mode on behalf of the calling process, or CLOCK_PROF for time that increments
|
sl@0
|
575 |
when the CPU is running in user or kernel mode.
|
sl@0
|
576 |
|
sl@0
|
577 |
As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME
|
sl@0
|
578 |
is supported for all the clock-based APIs.
|
sl@0
|
579 |
|
sl@0
|
580 |
The structure pointed to by tp is defined in
|
sl@0
|
581 |
@code
|
sl@0
|
582 |
#include <sys/time.h> as:
|
sl@0
|
583 |
@endcode
|
sl@0
|
584 |
|
sl@0
|
585 |
@code
|
sl@0
|
586 |
struct timespec {
|
sl@0
|
587 |
time_ttv_sec;/* seconds */
|
sl@0
|
588 |
longtv_nsec;/* and nanoseconds */
|
sl@0
|
589 |
};
|
sl@0
|
590 |
@endcode
|
sl@0
|
591 |
|
sl@0
|
592 |
The resolution (granularity) of a clock is returned by the clock_getres system call.
|
sl@0
|
593 |
This value is placed in a (non-NULL) *tp.
|
sl@0
|
594 |
|
sl@0
|
595 |
The clock_getcpuclockid system call returns ( in *clock_id ) the clock ID of the CPU-time clock of the process specified
|
sl@0
|
596 |
by pid. If pid is zero, the clock ID of the CPU-time clock of the process making
|
sl@0
|
597 |
the call is returned.
|
sl@0
|
598 |
|
sl@0
|
599 |
Examples:
|
sl@0
|
600 |
@code
|
sl@0
|
601 |
#include <time.h>
|
sl@0
|
602 |
#include <stdio.h>
|
sl@0
|
603 |
int clock_user()
|
sl@0
|
604 |
{
|
sl@0
|
605 |
struct timespec tp;
|
sl@0
|
606 |
int retval;
|
sl@0
|
607 |
clockid_t clockid;
|
sl@0
|
608 |
clock_getres (CLOCK_REALTIME, &tp;); // Call clock_getres
|
sl@0
|
609 |
printf ("Real time-clock resolution is %d seconds and %d nanoseconds
|
sl@0
|
610 |
", tp.tv_sec, tp.tv_nsec);
|
sl@0
|
611 |
clock_getcpuclockid (0 ,&clockid;); // Call clock_getcpuclockid with pid = 0
|
sl@0
|
612 |
printf ("The clock id for the current process is %d
|
sl@0
|
613 |
", clockid);
|
sl@0
|
614 |
tp.tv_sec = 0;
|
sl@0
|
615 |
tp.tv_nsec = 100;
|
sl@0
|
616 |
retval = clock_settime (CLOCK_REALTIME, &tp;); // Call clock_settime with 100ns
|
sl@0
|
617 |
printf ("clock_settime returned %d
|
sl@0
|
618 |
", retval);
|
sl@0
|
619 |
clock_gettime (CLOCK_REALTIME, &tp;); // Call clock_gettime to fill tp
|
sl@0
|
620 |
printf ("Time from real time-clock is %d seconds and %d nanoseconds
|
sl@0
|
621 |
", tp.tv_sec, tp.tv_nsec);
|
sl@0
|
622 |
return 0;
|
sl@0
|
623 |
}
|
sl@0
|
624 |
|
sl@0
|
625 |
@endcode
|
sl@0
|
626 |
Output
|
sl@0
|
627 |
@code
|
sl@0
|
628 |
Real time-clock resolution is 0 seconds and 1000000 nanoseconds
|
sl@0
|
629 |
The clock id for the current process is 0
|
sl@0
|
630 |
clock_settime returned 0
|
sl@0
|
631 |
Time from real time-clock is 0 seconds and 70663000 nanoseconds
|
sl@0
|
632 |
|
sl@0
|
633 |
@endcode
|
sl@0
|
634 |
@see adjtime()
|
sl@0
|
635 |
@see ctime()
|
sl@0
|
636 |
|
sl@0
|
637 |
@publishedAll
|
sl@0
|
638 |
@externallyDefinedApi
|
sl@0
|
639 |
*/
|
sl@0
|
640 |
|
sl@0
|
641 |
/** @fn clock_settime(clockid_t clock_id, const struct timespec *tp)
|
sl@0
|
642 |
@param clock_id
|
sl@0
|
643 |
@param tp
|
sl@0
|
644 |
|
sl@0
|
645 |
Refer to clock_gettime() for the documentation
|
sl@0
|
646 |
|
sl@0
|
647 |
@see adjtime()
|
sl@0
|
648 |
@see ctime()
|
sl@0
|
649 |
|
sl@0
|
650 |
@capability Deferred @ref User::SetUTCTime(const TTime &aUTCTime)
|
sl@0
|
651 |
|
sl@0
|
652 |
@publishedAll
|
sl@0
|
653 |
@externallyDefinedApi
|
sl@0
|
654 |
*/
|
sl@0
|
655 |
|
sl@0
|
656 |
/** @fn nanosleep(const struct timespec *req, struct timespec *rem)
|
sl@0
|
657 |
@param req
|
sl@0
|
658 |
@param rem
|
sl@0
|
659 |
@return If the nanosleep system call returns because the requested time has elapsed, the value
|
sl@0
|
660 |
returned will be zero. If rem is non- NULL, the timespec structure it references is updated to contain the
|
sl@0
|
661 |
unslept amount (the request time minus the time actually slept).
|
sl@0
|
662 |
|
sl@0
|
663 |
The nanosleep system call
|
sl@0
|
664 |
causes the process to sleep for the specified time.
|
sl@0
|
665 |
Currently only microsecond sleep resolution can be obtained.
|
sl@0
|
666 |
|
sl@0
|
667 |
|
sl@0
|
668 |
|
sl@0
|
669 |
Examples:
|
sl@0
|
670 |
@code
|
sl@0
|
671 |
/*
|
sl@0
|
672 |
* Detailed description: Sample usage of nanosleep system call.
|
sl@0
|
673 |
*/
|
sl@0
|
674 |
#include <stdio.h>
|
sl@0
|
675 |
#include <time.h>
|
sl@0
|
676 |
int main()
|
sl@0
|
677 |
{
|
sl@0
|
678 |
struct timespec tim, tim2;
|
sl@0
|
679 |
tim.tv_sec = 1;
|
sl@0
|
680 |
tim.tv_nsec = 500;
|
sl@0
|
681 |
if(nanosleep(&tim; , &tim2;) < 0 ) {
|
sl@0
|
682 |
printf("Nano sleep system call failed
|
sl@0
|
683 |
");
|
sl@0
|
684 |
return -1;
|
sl@0
|
685 |
}
|
sl@0
|
686 |
printf("Nano sleep successfull
|
sl@0
|
687 |
");
|
sl@0
|
688 |
return 0;
|
sl@0
|
689 |
}
|
sl@0
|
690 |
|
sl@0
|
691 |
@endcode
|
sl@0
|
692 |
Output
|
sl@0
|
693 |
@code
|
sl@0
|
694 |
Nano sleep successfull
|
sl@0
|
695 |
|
sl@0
|
696 |
@endcode
|
sl@0
|
697 |
@see sleep()
|
sl@0
|
698 |
|
sl@0
|
699 |
|
sl@0
|
700 |
|
sl@0
|
701 |
|
sl@0
|
702 |
@publishedAll
|
sl@0
|
703 |
@externallyDefinedApi
|
sl@0
|
704 |
*/
|
sl@0
|
705 |
|
sl@0
|
706 |
/** @fn clock_getcpuclockid(pid_t pid, clockid_t* clock_id)
|
sl@0
|
707 |
@param pid
|
sl@0
|
708 |
@param clock_id
|
sl@0
|
709 |
|
sl@0
|
710 |
Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME
|
sl@0
|
711 |
is supported for all the clock-based APIs. Any value for pid except "0" is considered as invalid
|
sl@0
|
712 |
and for "0" the supported 'clock_id' i.e, CLOCK_REALTIME is returned.
|
sl@0
|
713 |
|
sl@0
|
714 |
Refer to clock_gettime() for the documentation
|
sl@0
|
715 |
@see adjtime()
|
sl@0
|
716 |
@see ctime()
|
sl@0
|
717 |
|
sl@0
|
718 |
@publishedAll
|
sl@0
|
719 |
@externallyDefinedApi
|
sl@0
|
720 |
*/
|
sl@0
|
721 |
|
sl@0
|
722 |
/** @fn clock_nanosleep (clockid_t clock_id, int flags,
|
sl@0
|
723 |
const struct timespec *rqtp, struct timespec *rmtp)
|
sl@0
|
724 |
@param clock_id
|
sl@0
|
725 |
@param flags
|
sl@0
|
726 |
@param rqtp
|
sl@0
|
727 |
@param rmtp
|
sl@0
|
728 |
|
sl@0
|
729 |
For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/clock_nanosleep.html
|
sl@0
|
730 |
|
sl@0
|
731 |
Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME
|
sl@0
|
732 |
is supported for all the clock-based APIs.
|
sl@0
|
733 |
|
sl@0
|
734 |
@publishedAll
|
sl@0
|
735 |
@externallyDefinedApi
|
sl@0
|
736 |
*/
|
sl@0
|
737 |
|
sl@0
|
738 |
/** @fn asctime_r(const struct tm *tm, char *buf)
|
sl@0
|
739 |
@param tm
|
sl@0
|
740 |
@param buf
|
sl@0
|
741 |
|
sl@0
|
742 |
Refer to ctime() for the documentation
|
sl@0
|
743 |
@see gettimeofday()
|
sl@0
|
744 |
@see getenv()
|
sl@0
|
745 |
@see time()
|
sl@0
|
746 |
@see tzset()
|
sl@0
|
747 |
|
sl@0
|
748 |
|
sl@0
|
749 |
|
sl@0
|
750 |
|
sl@0
|
751 |
@publishedAll
|
sl@0
|
752 |
@externallyDefinedApi
|
sl@0
|
753 |
*/
|
sl@0
|
754 |
|
sl@0
|
755 |
/** @fn ctime_r(const time_t *clock, char *buf)
|
sl@0
|
756 |
@param clock
|
sl@0
|
757 |
@param buf
|
sl@0
|
758 |
|
sl@0
|
759 |
Refer to ctime() for the documentation
|
sl@0
|
760 |
@see gettimeofday()
|
sl@0
|
761 |
@see getenv()
|
sl@0
|
762 |
@see time()
|
sl@0
|
763 |
@see tzset()
|
sl@0
|
764 |
|
sl@0
|
765 |
|
sl@0
|
766 |
|
sl@0
|
767 |
|
sl@0
|
768 |
@publishedAll
|
sl@0
|
769 |
@externallyDefinedApi
|
sl@0
|
770 |
*/
|
sl@0
|
771 |
|
sl@0
|
772 |
/** @fn gmtime_r(const time_t *clock, struct tm *result)
|
sl@0
|
773 |
@param clock
|
sl@0
|
774 |
@param result
|
sl@0
|
775 |
|
sl@0
|
776 |
Refer to ctime() for the documentation
|
sl@0
|
777 |
@see gettimeofday()
|
sl@0
|
778 |
@see getenv()
|
sl@0
|
779 |
@see time()
|
sl@0
|
780 |
@see tzset()
|
sl@0
|
781 |
|
sl@0
|
782 |
|
sl@0
|
783 |
|
sl@0
|
784 |
|
sl@0
|
785 |
@publishedAll
|
sl@0
|
786 |
@externallyDefinedApi
|
sl@0
|
787 |
*/
|
sl@0
|
788 |
|
sl@0
|
789 |
|
sl@0
|
790 |
/** @fn localtime_r(const time_t *clock, struct tm *result)
|
sl@0
|
791 |
@param clock
|
sl@0
|
792 |
@param result
|
sl@0
|
793 |
|
sl@0
|
794 |
Refer to ctime() for the documentation
|
sl@0
|
795 |
@see gettimeofday()
|
sl@0
|
796 |
@see getenv()
|
sl@0
|
797 |
@see time()
|
sl@0
|
798 |
@see tzset()
|
sl@0
|
799 |
|
sl@0
|
800 |
|
sl@0
|
801 |
|
sl@0
|
802 |
|
sl@0
|
803 |
@publishedAll
|
sl@0
|
804 |
@externallyDefinedApi
|
sl@0
|
805 |
*/
|
sl@0
|
806 |
|
sl@0
|
807 |
|
sl@0
|
808 |
/** @fn strptime(const char * buf, const char * fmt, struct tm * tm)
|
sl@0
|
809 |
@param buf
|
sl@0
|
810 |
@param fmt
|
sl@0
|
811 |
@param tm
|
sl@0
|
812 |
@return Upon successful completion, strptime returns the pointer to the first character in buf that has not been required to satisfy the specified conversions in fmt .
|
sl@0
|
813 |
It returns NULL if one of the conversions failed.
|
sl@0
|
814 |
|
sl@0
|
815 |
The strptime function parses the string in the buffer buf according to the string pointed to by fmt ,
|
sl@0
|
816 |
and fills in the elements of the structure pointed to by tm .
|
sl@0
|
817 |
The resulting values will be relative to the local time zone.
|
sl@0
|
818 |
Thus, it can be considered the reverse operation of strftime .
|
sl@0
|
819 |
|
sl@0
|
820 |
The fmt string consists of zero or more conversion specifications and
|
sl@0
|
821 |
ordinary characters.
|
sl@0
|
822 |
All ordinary characters are matched exactly with the buffer, where
|
sl@0
|
823 |
white space in the fmt string will match any amount of white space
|
sl@0
|
824 |
in the buffer.
|
sl@0
|
825 |
All conversion specifications are identical to those described in strftime .
|
sl@0
|
826 |
|
sl@0
|
827 |
Two-digit year values, including formats \%y and \%D ,
|
sl@0
|
828 |
are now interpreted as beginning at 1969 per POSIX requirements.
|
sl@0
|
829 |
Years 69-00 are interpreted in the 20th century (1969-2000), years
|
sl@0
|
830 |
01-68 in the 21st century (2001-2068).
|
sl@0
|
831 |
|
sl@0
|
832 |
If the fmt string does not contain enough conversion specifications to completely
|
sl@0
|
833 |
specify the resulting struct tm ,
|
sl@0
|
834 |
the unspecified members of tm are left untouched.
|
sl@0
|
835 |
For example, if format is "\%H:\%M:\%S",
|
sl@0
|
836 |
only tm_hour , tm_sec and tm_min will be modified.
|
sl@0
|
837 |
If time relative to today is desired, initialize the tm structure with today's date before passing it to strptime .
|
sl@0
|
838 |
|
sl@0
|
839 |
Examples:
|
sl@0
|
840 |
@code
|
sl@0
|
841 |
#include <string.h>
|
sl@0
|
842 |
#include <stdio.h>
|
sl@0
|
843 |
#include <time.h>
|
sl@0
|
844 |
#include <locale.h>
|
sl@0
|
845 |
int main()
|
sl@0
|
846 |
{
|
sl@0
|
847 |
struct tm tm;
|
sl@0
|
848 |
char buf[255];
|
sl@0
|
849 |
char *locale;
|
sl@0
|
850 |
locale = setlocale(LC_TIME,"en_GB.ISO-8859-1");
|
sl@0
|
851 |
if( locale != NULL)
|
sl@0
|
852 |
{
|
sl@0
|
853 |
strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm;);
|
sl@0
|
854 |
printf("sec = %d min = %d hours = %d
|
sl@0
|
855 |
Year = %d Month = %d day = %d
|
sl@0
|
856 |
",
|
sl@0
|
857 |
tm.tm_sec,tm.tm_min,tm.tm_hour,tm.tm_year,tm.tm_mon,tm.tm_mday);
|
sl@0
|
858 |
strftime(buf, sizeof(buf), "%d %B %Y %H:%M:%S", &tm;);
|
sl@0
|
859 |
puts(buf);
|
sl@0
|
860 |
strptime("Mon","%a", &tm;);
|
sl@0
|
861 |
strftime(buf, sizeof(buf), "%a", &tm;);
|
sl@0
|
862 |
puts(buf);
|
sl@0
|
863 |
}
|
sl@0
|
864 |
else
|
sl@0
|
865 |
printf("Failed to set locale");
|
sl@0
|
866 |
}
|
sl@0
|
867 |
|
sl@0
|
868 |
@endcode
|
sl@0
|
869 |
Output
|
sl@0
|
870 |
@code
|
sl@0
|
871 |
sec = 1 min = 31 hours = 18
|
sl@0
|
872 |
Year = 101 Month = 10 day = 12
|
sl@0
|
873 |
12 November 2001 18:31:01
|
sl@0
|
874 |
Mon
|
sl@0
|
875 |
|
sl@0
|
876 |
@endcode
|
sl@0
|
877 |
@see scanf()
|
sl@0
|
878 |
@see strftime()
|
sl@0
|
879 |
|
sl@0
|
880 |
|
sl@0
|
881 |
Bugs:
|
sl@0
|
882 |
|
sl@0
|
883 |
Both the \%e and \%l format specifiers may incorrectly scan one too many digits
|
sl@0
|
884 |
if the intended values comprise only a single digit
|
sl@0
|
885 |
and that digit is followed immediately by another digit.
|
sl@0
|
886 |
Both specifiers accept zero-padded values,
|
sl@0
|
887 |
even though they are both defined as taking unpadded values.
|
sl@0
|
888 |
|
sl@0
|
889 |
The \%p format specifier has no effect unless it is parsed after hour-related specifiers.
|
sl@0
|
890 |
Specifying \%l without \%p will produce undefined results.
|
sl@0
|
891 |
Note that 12AM
|
sl@0
|
892 |
(ante meridiem)
|
sl@0
|
893 |
is taken as midnight
|
sl@0
|
894 |
and 12PM
|
sl@0
|
895 |
(post meridiem)
|
sl@0
|
896 |
is taken as noon.
|
sl@0
|
897 |
|
sl@0
|
898 |
The \%U and \%W format specifiers accept any value within the range 00 to 53
|
sl@0
|
899 |
without validating against other values supplied (like month
|
sl@0
|
900 |
or day of the year, for example).
|
sl@0
|
901 |
|
sl@0
|
902 |
The \%Z format specifier only accepts time zone abbreviations of the local time zone,
|
sl@0
|
903 |
or the value "GMT".
|
sl@0
|
904 |
This limitation is because of ambiguity due to of the over loading of time
|
sl@0
|
905 |
zone abbreviations.
|
sl@0
|
906 |
One such example is EST which is both Eastern Standard Time and Eastern Australia Summer Time.
|
sl@0
|
907 |
|
sl@0
|
908 |
The strptime function does not correctly handle multibyte characters in the fmt argument.
|
sl@0
|
909 |
|
sl@0
|
910 |
|
sl@0
|
911 |
@publishedAll
|
sl@0
|
912 |
@externallyDefinedApi
|
sl@0
|
913 |
*/
|
sl@0
|
914 |
|
sl@0
|
915 |
/** @fn timer_create (clockid_t __clock_id,
|
sl@0
|
916 |
struct sigevent *__restrict __evp,
|
sl@0
|
917 |
timer_t *__restrict __timerid)
|
sl@0
|
918 |
@param __clock_id
|
sl@0
|
919 |
@param __evp
|
sl@0
|
920 |
@param __timerid
|
sl@0
|
921 |
|
sl@0
|
922 |
For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/timer_create.html
|
sl@0
|
923 |
|
sl@0
|
924 |
Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME
|
sl@0
|
925 |
is supported for all the clock-based APIs.
|
sl@0
|
926 |
|
sl@0
|
927 |
@see timer_settime()
|
sl@0
|
928 |
@see timer_delete()
|
sl@0
|
929 |
|
sl@0
|
930 |
@publishedAll
|
sl@0
|
931 |
@externallyDefinedApi
|
sl@0
|
932 |
*/
|
sl@0
|
933 |
|
sl@0
|
934 |
/** @fn timer_delete (timer_t __timerid)
|
sl@0
|
935 |
@param __timerid
|
sl@0
|
936 |
|
sl@0
|
937 |
For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/timer_delete.html
|
sl@0
|
938 |
|
sl@0
|
939 |
@see timer_create()
|
sl@0
|
940 |
@see timer_settime()
|
sl@0
|
941 |
|
sl@0
|
942 |
@publishedAll
|
sl@0
|
943 |
@externallyDefinedApi
|
sl@0
|
944 |
*/
|
sl@0
|
945 |
|
sl@0
|
946 |
/** @fn timer_settime(timer_t __timerid, int __flags,
|
sl@0
|
947 |
const struct itimerspec *__restrict __value,
|
sl@0
|
948 |
struct itimerspec *__restrict __ovalue)
|
sl@0
|
949 |
@param __timerid
|
sl@0
|
950 |
@param __flags
|
sl@0
|
951 |
@param __value
|
sl@0
|
952 |
@param __ovalue
|
sl@0
|
953 |
|
sl@0
|
954 |
For full documentation, see http://www.opengroup.org/onlinepubs/009695399/functions/timer_settime.html
|
sl@0
|
955 |
|
sl@0
|
956 |
Note: This description also covers the timer_gettime() and timer_getoverrun() functions.
|
sl@0
|
957 |
|
sl@0
|
958 |
Note: As Symbian OS exposes only 'wall clock time' at user level, only CLOCK_REALTIME
|
sl@0
|
959 |
is supported for all the clock-based APIs. At the user level, Symbian OS supports upto a
|
sl@0
|
960 |
maximum of 1 ms resolution timer (RTimer::HighRes ()) upon which the timer emulation solution is based.
|
sl@0
|
961 |
As the re-registrations for a periodic timer happen in the user mode, the timer expirations
|
sl@0
|
962 |
might show up a possible unspecified latency.
|
sl@0
|
963 |
|
sl@0
|
964 |
Examples:
|
sl@0
|
965 |
@code
|
sl@0
|
966 |
/*
|
sl@0
|
967 |
* Detailed description:
|
sl@0
|
968 |
*/
|
sl@0
|
969 |
#include <time.h>
|
sl@0
|
970 |
#include <stdio.h>
|
sl@0
|
971 |
#include <signal.h>
|
sl@0
|
972 |
#include <pthread.h>
|
sl@0
|
973 |
#include <unistd.h>
|
sl@0
|
974 |
|
sl@0
|
975 |
void sighler (union sigval val)
|
sl@0
|
976 |
{
|
sl@0
|
977 |
printf("In the handler with val:%d\n", val.sival_int);
|
sl@0
|
978 |
}
|
sl@0
|
979 |
|
sl@0
|
980 |
int main()
|
sl@0
|
981 |
{
|
sl@0
|
982 |
timer_t timerid;
|
sl@0
|
983 |
struct sigevent sig;
|
sl@0
|
984 |
|
sl@0
|
985 |
pthread_attr_t attr;
|
sl@0
|
986 |
pthread_attr_init( &attr );
|
sl@0
|
987 |
|
sl@0
|
988 |
sig.sigev_notify = SIGEV_THREAD;
|
sl@0
|
989 |
sig.sigev_notify_function = sighler;
|
sl@0
|
990 |
sig.sigev_value.sival_int =20;
|
sl@0
|
991 |
sig.sigev_notify_attributes = &attr;
|
sl@0
|
992 |
|
sl@0
|
993 |
if(0 == timer_create(CLOCK_REALTIME, &sig, &timerid))
|
sl@0
|
994 |
{
|
sl@0
|
995 |
struct itimerspec in, out;
|
sl@0
|
996 |
|
sl@0
|
997 |
in.it_value.tv_sec = 1;
|
sl@0
|
998 |
in.it_value.tv_nsec = 0;
|
sl@0
|
999 |
|
sl@0
|
1000 |
in.it_interval.tv_sec = 0;
|
sl@0
|
1001 |
in.it_interval.tv_nsec = 0;
|
sl@0
|
1002 |
|
sl@0
|
1003 |
if(0 == timer_settime(timerid, 0, &in, &out))
|
sl@0
|
1004 |
{
|
sl@0
|
1005 |
sleep(3); //wait for the timer expirations...
|
sl@0
|
1006 |
}
|
sl@0
|
1007 |
else
|
sl@0
|
1008 |
{
|
sl@0
|
1009 |
printf("timer_settime () failed with err:%d\n", errno);
|
sl@0
|
1010 |
}
|
sl@0
|
1011 |
|
sl@0
|
1012 |
timer_delete(timerid);
|
sl@0
|
1013 |
}
|
sl@0
|
1014 |
else
|
sl@0
|
1015 |
{
|
sl@0
|
1016 |
printf("timer_create () failed with err:%d\n", errno);
|
sl@0
|
1017 |
}
|
sl@0
|
1018 |
|
sl@0
|
1019 |
return 0;
|
sl@0
|
1020 |
}
|
sl@0
|
1021 |
|
sl@0
|
1022 |
@endcode
|
sl@0
|
1023 |
Output
|
sl@0
|
1024 |
@code
|
sl@0
|
1025 |
In the handler with val:20
|
sl@0
|
1026 |
|
sl@0
|
1027 |
@endcode
|
sl@0
|
1028 |
@see timer_create()
|
sl@0
|
1029 |
@see timer_delete()
|
sl@0
|
1030 |
@see clock_gettime()
|
sl@0
|
1031 |
|
sl@0
|
1032 |
@publishedAll
|
sl@0
|
1033 |
@externallyDefinedApi
|
sl@0
|
1034 |
*/
|
sl@0
|
1035 |
|
sl@0
|
1036 |
/** @fn timer_gettime (timer_t __timerid, struct itimerspec *__value)
|
sl@0
|
1037 |
@param __timerid
|
sl@0
|
1038 |
@param __value
|
sl@0
|
1039 |
|
sl@0
|
1040 |
For documentation refer to timer_settime().
|
sl@0
|
1041 |
|
sl@0
|
1042 |
@see timer_create()
|
sl@0
|
1043 |
@see timer_delete()
|
sl@0
|
1044 |
|
sl@0
|
1045 |
@publishedAll
|
sl@0
|
1046 |
@externallyDefinedApi
|
sl@0
|
1047 |
*/
|
sl@0
|
1048 |
|
sl@0
|
1049 |
/** @fn timer_getoverrun (timer_t __timerid)
|
sl@0
|
1050 |
@param __timerid
|
sl@0
|
1051 |
|
sl@0
|
1052 |
For documentation refer to timer_settime().
|
sl@0
|
1053 |
|
sl@0
|
1054 |
@see timer_create()
|
sl@0
|
1055 |
@see timer_delete()
|
sl@0
|
1056 |
|
sl@0
|
1057 |
@publishedAll
|
sl@0
|
1058 |
@externallyDefinedApi
|
sl@0
|
1059 |
*/
|
sl@0
|
1060 |
|
sl@0
|
1061 |
/** @def CLOCK_REALTIME
|
sl@0
|
1062 |
|
sl@0
|
1063 |
This clock represents the realtime clock for the system.
|
sl@0
|
1064 |
|
sl@0
|
1065 |
@publishedAll
|
sl@0
|
1066 |
@externallyDefinedApi
|
sl@0
|
1067 |
*/
|
sl@0
|
1068 |
|
sl@0
|
1069 |
/** @def CLOCK_VIRTUAL
|
sl@0
|
1070 |
|
sl@0
|
1071 |
This clock represents the amount of time (in seconds and nanoseconds) that the calling process has spent executing code in the user's context. It is a per-process clock. It cannot be set by the user.
|
sl@0
|
1072 |
|
sl@0
|
1073 |
@publishedAll
|
sl@0
|
1074 |
@externallyDefinedApi
|
sl@0
|
1075 |
*/
|
sl@0
|
1076 |
|
sl@0
|
1077 |
/** @def TIMER_ABSTIME
|
sl@0
|
1078 |
|
sl@0
|
1079 |
absolute timer
|
sl@0
|
1080 |
|
sl@0
|
1081 |
@publishedAll
|
sl@0
|
1082 |
@externallyDefinedApi
|
sl@0
|
1083 |
*/
|
sl@0
|
1084 |
|
sl@0
|
1085 |
/** @struct tm
|
sl@0
|
1086 |
|
sl@0
|
1087 |
Contains the following members,
|
sl@0
|
1088 |
|
sl@0
|
1089 |
@publishedAll
|
sl@0
|
1090 |
@externallyDefinedApi
|
sl@0
|
1091 |
*/
|
sl@0
|
1092 |
|
sl@0
|
1093 |
/** @var tm::tm_sec
|
sl@0
|
1094 |
seconds after the minute
|
sl@0
|
1095 |
*/
|
sl@0
|
1096 |
|
sl@0
|
1097 |
/** @var tm::tm_min
|
sl@0
|
1098 |
minutes after the hour
|
sl@0
|
1099 |
*/
|
sl@0
|
1100 |
|
sl@0
|
1101 |
/** @var tm::tm_hour
|
sl@0
|
1102 |
hours since midnight
|
sl@0
|
1103 |
*/
|
sl@0
|
1104 |
|
sl@0
|
1105 |
/** @var tm::tm_mday
|
sl@0
|
1106 |
day of the month
|
sl@0
|
1107 |
*/
|
sl@0
|
1108 |
|
sl@0
|
1109 |
/** @var tm::tm_mon
|
sl@0
|
1110 |
months since January
|
sl@0
|
1111 |
*/
|
sl@0
|
1112 |
|
sl@0
|
1113 |
/** @var tm::tm_year
|
sl@0
|
1114 |
years since 1900
|
sl@0
|
1115 |
*/
|
sl@0
|
1116 |
|
sl@0
|
1117 |
/** @var tm::tm_wday
|
sl@0
|
1118 |
days since Sunday
|
sl@0
|
1119 |
*/
|
sl@0
|
1120 |
|
sl@0
|
1121 |
/** @var tm::tm_yday
|
sl@0
|
1122 |
days since January 1
|
sl@0
|
1123 |
*/
|
sl@0
|
1124 |
|
sl@0
|
1125 |
/** @var tm::tm_isdst
|
sl@0
|
1126 |
Daylight Savings Time flag
|
sl@0
|
1127 |
*/
|
sl@0
|
1128 |
|
sl@0
|
1129 |
/** @var tm::tm_gmtoff
|
sl@0
|
1130 |
offset from UTC in seconds
|
sl@0
|
1131 |
*/
|
sl@0
|
1132 |
|
sl@0
|
1133 |
/** @var tm::tm_zone
|
sl@0
|
1134 |
timezone abbreviation
|
sl@0
|
1135 |
*/
|
sl@0
|
1136 |
|
sl@0
|
1137 |
|
sl@0
|
1138 |
/** @fn time_t timegm(struct tm *tmp)
|
sl@0
|
1139 |
|
sl@0
|
1140 |
@param tmp
|
sl@0
|
1141 |
|
sl@0
|
1142 |
Description:
|
sl@0
|
1143 |
This function is inverses for gmtime.
|
sl@0
|
1144 |
Converts struct tm to time_t, assuming the data in tm is UTC rather than local timezone.
|
sl@0
|
1145 |
|
sl@0
|
1146 |
@see gmtime()
|
sl@0
|
1147 |
@see localtime()
|
sl@0
|
1148 |
@see mktime()
|
sl@0
|
1149 |
@see tzset()
|
sl@0
|
1150 |
|
sl@0
|
1151 |
@publishedAll
|
sl@0
|
1152 |
@externallyDefinedApi
|
sl@0
|
1153 |
*/
|