# Include <stdio. h>
# Include <time. h>
Int main (){
Struct TM;
Char Buf [255];
Strptime ("2001-11-12 18:31:01", "% Y-% m-% d % H: % m: % s", & TM );
Strftime (BUF, sizeof (BUF), "% d % B % Y % H: % m", & TM );
Puts (BUF );
Return 0;
}
These two functions are the format control functions of the time and date, which seem to be the opposite in terms of functionality.
Size_t strftime (char * s, size_t maxsize, char * format, const struct TM * timeptr)
Purpose: strftime format a tm structure as a string
Parameter: format is the output data format.
Char * strptime (const char * Buf, const char * format, struct TM * timeptr)
Purpose: strptime is to format a string into a TM structure.
Parameter: the time when the Buf is to be modified, generally the gps time.
Format is the data format, which must be consistent with the Buf time format. Otherwise, a segment error occurs.
% |
Day of the week |
% |
Full name of the day of the week |
% B |
Abbreviated month format |
% B |
Full name of month |
% C |
Date and Time |
% D |
Date in month, 0-31 |
% H |
Hour, 00-23 |
% I |
Hour in decimal format, 01-12 |
% J |
The date in the year, 001-366 |
% M |
Month in year, 01-12 |
% M |
Minute, 00-59 |
% P |
Morning or afternoon |
% S |
Seconds, 00-60 |
% U |
Day of the week, 1-7 |
% W |
Day of the week, 0-6 |
% X |
Date in local format |