C语言函数—asctime

函数名

asctime

功 能

转换日期和时间为ASCII码

用 法

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("%sn", str); 

   return 0; 
}   

如果引用本站的原创文章,请注明原文链接:,本站保留追究责任的权利!

发表评论