Function name : asctime
Header file : <time.h>
Function prototype : char *asctime(const struct tm *t);
Function : Convert the given date and time into ASCII code
Parameters : tm is the structure to be converted
Return value : Returns the converted string pointer
Replenish :
1. Convert the given calendar time tm to a text representation in the following fixed 25-character format:
DDD MMM dd hh:mm:ss YYYY
DDD A day of the week, such as Mon
MMM month, such as Jan
dd day of the month (1,2,…,31)
hh hours (1,2,…,24)
mm minutes (1,2,…,59)
ss seconds (1,2,…,59)
YYYY year +1900
If any member *time_ptr is outside its normal range, the behavior is undefined
The behavior is unambiguous if the indicated time_ptr->tm_year calendar year exceeds 4 digits or is less than 1000 years.
This function does not support localization and cannot remove newlines.
2. struct *tm{
int tm_sec; //seconds
int tm_min; //minutes
int tm_hour; //hour
int tm_mday; //The number of days in a month
int tm_mon; //month
int tm_year; //year
int tm_wday; //week
int tm_yday; //The number of days in a year
int tm_isdst; // Daylight saving time identifier. When daylight saving time is implemented, tm_isdst is positive. When daylight saving time is not implemented, tm_isdst is 0; when the situation is not understood, tm_isdst() is negative.
}
Program example: Convert the time structure t into a string time description and output the result
#include<time.h>#include<stdio.h>#include<string.h>intmain(void){structtmt;charstr[80];t.tm_sec=1;t.tm_min=30;t.tm_hour=9 ;t.tm_mda y=22;t.tm_mon=11;t.tm_year=56;t.tm_wday=4;t.tm_yday=0;//Do not display t.tm_isdst=0;//Do not implement daylight saving time strcpy(str,asctime( &t));printf(%sn,str);return0;}
Running results:
ThuDec2209:30:011956