asctime 时间文本格式

头文件

#include <time.h>

语法

char *asctime( const struct tm *ptr );

功能

函数将 ptr 所指向的时间结构转换成下列字符串: 

day month date hours:minutes:seconds year\n\0

示例

#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\n", str);

   return 0;
}

输出结果:

Thu Dec 22 09:30:01 1956
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号