C Library Functions -asctime()

C Standard Library - <time.h>

Description

C Library Functionschar *asctime(const struct tm *timeptr)Returns a pointer to a string that represents the structure.struct timeptrdate and time.

Declaration

Below is the declaration of the asctime() function.

char *asctime(const struct tm *timeptr)

Parameter

timeptrIt is a pointer to a tm structure that contains the calendar time broken down into the following parts:

struct tm {
   int tm_sec;         /* 秒,范围从 0 到 59                */
   int tm_min;         /* 分,范围从 0 到 59                */
   int tm_hour;        /* 小时,范围从 0 到 23                */
   int tm_mday;        /* 一月中的第几天,范围从 1 到 31                    */
   int tm_mon;         /* 月份,范围从 0 到 11                */
   int tm_year;        /* 自 1900 起的年数                */
   int tm_wday;        /* 一周中的第几天,范围从 0 到 6                */
   int tm_yday;        /* 一年中的第几天,范围从 0 到 365                    */
   int tm_isdst;       /* 夏令时                        */    
};

Return Value

This function returns a C string containing the date and time information in a human-readable format.Www Mmm dd hh:mm:ss yyyy, where,WwwIndicates the day of the week,MmmIs the month represented by letters,ddIndicates the day of the month,hh:mm:ssrepresents time,yyyyrepresents the year.

Example

The following example demonstrates the usage of the asctime() function.

Example

#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);
}

Let us compile and run the above program, which will produce the following result:

Sat Mar 25 06:10:10 1989

C Standard Library - <time.h>

other extensions