目录

char *asctime(const struct tm *timeptr)

描述 (Description)

C库函数char *asctime(const struct tm *timeptr)返回一个指向字符串的指针,该字符串表示结构struct timeptr的日期和时间。

声明 (Declaration)

以下是asctime()函数的声明。

char *asctime(const struct tm *timeptr)

参数 (Parameters)

timeptr是指向tm结构的指针,其中包含分解为其组件的日历时间,如下所示 -

struct tm {
   int tm_sec;         /* seconds,  range 0 to 59          */
   int tm_min;         /* minutes, range 0 to 59           */
   int tm_hour;        /* hours, range 0 to 23             */
   int tm_mday;        /* day of the month, range 1 to 31  */
   int tm_mon;         /* month, range 0 to 11             */
   int tm_year;        /* The number of years since 1900   */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365  */
   int tm_isdst;       /* daylight saving time             */
};

返回值 (Return Value)

此函数以人类可读的格式返回包含日期和时间信息的C字符串Www Mmm dd hh:mm:ss yyyy ,其中Www是工作日, Mmm是月份的字母, dd是月份的日期, hh:mm:ss是时候了,而且是一年中的yyyy

例子 (Example)

以下示例显示了asctime()函数的用法。

#include <stdio.h>
#include <string.h>
#include <time.h>
int main () {
   struct tm t;
   t.tm_sec    = 10;
   t.tm_min    = 10;
   t.tm_hour   = 6;
   t.tm_mday   = 25;
   t.tm_mon    = 2;
   t.tm_year   = 89;
   t.tm_wday   = 6;
   puts(asctime(&t));
   return(0);
}

让我们编译并运行上面的程序,它将产生以下结果 -

Sat Mar 25 06:10:10 1989
↑回到顶部↑
WIKI教程 @2018