词条 | asctime |
释义 | 函数名: asctime 功 能: 转换日期和时间为相应的字符串(英文简写形式) 用 法: char *asctime(const struct tm *tblock); 程序例: #include <stdio.h> #include <string.h> #include <time.h> int main(void) { struct tm t; char str[80]; /* sample loading of tm structure */ t.tm_sec = 1; /* Seconds */ t.tm_min = 30; /* Minutes */ t.tm_hour = 9; /* Hour */ t.tm_mday = 22; /* Day of the Month */ t.tm_mon = 11; /* Month */ t.tm_year = 56; /* Year - does not include century */ t.tm_wday = 4; /* Day of the week */ t.tm_yday = 0; /* Does not show in asctime */ t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */ /* converts structure to null terminated string */ strcpy(str, asctime(&t)); printf("%s\", str); return 0; } 英文详解:Synopsis #include <time.h> char *asctime(const struct tm *timeptr); Description The asctime function converts the broken-down time in the structure pointed to by timeptr into a string in the form Sun Sep 16 01:03:52 1973\\\0 using the equivalent of the following algorithm. char *asctime(const struct tm *timeptr) { static const char wday_name[7][3] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; static const char mon_name[12][3] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static char result[26]; sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\", wday_name[timeptr->tm_wday], mon_name[timeptr->tm_mon], timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, 1900 + timeptr->tm_year ); return result; } Returns The asctime function returns a pointer to the string. Example : #include <stdio.h> #include <time.h> void main(void) { struct tm *newtime; time_t ltime; time (<ime); /* Get the time in seconds */ newtime = localtime(<ime); /* convert it to the structure tm */ printf("The current time and date are %s", asctime(newtime));/* print the local time as a string */ } The current time and date are Mon Dec 28 12:33:50 1998 |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。