This function is compatible with the following targets:
|
|
#include <time.h>
size_t strftime(char *s, size_t maxsize,  
const char *format,
const struct tm *timeptr);
Parameters for this facility are:
The s argument is a pointer to the array to hold the formatted time.
The maxsize argument specifies the maximum length of the formatted character array.
The timeptr argument points to a tm structure containing the calendar time to convert and format.
If any of the specified values are outside the normal range, the characters stored are unspecified.
NOTE
|
Char
|
Description
|
|---|---|
#include <time.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
time_t lclTime;
struct tm *now;
char ts[256]; /* time string */
lclTime = time(NULL);
now = localtime(&lclTime);
strftime(ts, 256,
"Today's abr.name is %a", now);
puts(ts);
strftime(ts, 256,
"Today's full name is %A", now);
puts(ts);
strftime(ts, 256,
"Today's aabr.month name is %b", now);
puts(ts);
strftime(ts, 256,
"Today's full month name is %B", now);
puts(ts);
strftime(ts, 256,
"Today's date and time is %c",now);
puts(ts);
strftime(ts, 256,
"The day of the month is %d", now);
puts(ts);
strftime(ts, 256,
"The 24-hour clock hour is %H",now);
puts(ts);
strftime(ts, 256,
"The 12-hour clock hour is %H", now);
puts(ts);
strftime(ts, 256,
"Today's day number is %j", now);
puts(ts);
strftime(ts, 256,
"Today's month number is %m", now);
puts(ts);
strftime(ts, 256,
"The minute is %M", now);
puts(ts);
strftime(ts, 256,
"The AM/PM is %p", now);
puts(ts);
strftime(ts, 256,
"The second is %S", now);
puts(ts);
strftime(ts, 256,
"The week number of the year,\
starting on a Sunday is %U", now);
puts(ts);
strftime(ts, 256,
"The number of the week is %w", now);
puts(ts);
strftime(ts, 256, "The week number of the year,\
starting on a Monday is %W", now);
puts(ts);
strftime(ts, 256, "The date is %x", now);
puts(ts);
strftime(ts, 256, "The time is %X", now);
puts(ts);
strftime(ts, 256,
"The last two digits of the year are %y", now);
puts(ts);
strftime(ts, 256, "The year is %Y", now);
puts(ts);
strftime(ts, 256, "%Z", now);
if (strlen(ts) == 0)
printf("The time zone cannot be determined\n");
else
printf("The time zone is %s\n", ts);
return 0;
}
Results
Today's abr.name is Wed
Today's full name is Wednesday
Today's aabr.month name is Apr
Today's full month name is April
Today's date and time is Wednesday April 05 10:50:44 2000
The day of the month is 05
The 24-hour clock hour is 10
The 12-hour clock hour is 10
Today's day number is 096
Today's month number is 04
The minute is 50
The AM/PM is am
The second is 44
The week number of the year,starting on a Sunday is 14
The number of the week is 3
The week number of the year,starting on a Monday is 14
The date is Wednesday April 05 2000
The time is 10:50:44
The last two digits of the year are 00
The year is 2000
The time zone cannot be determined
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000