Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

asctime - Date and time

&pagelevel(4)&pagelevel

Definition

#include <time.h>

char *asctime(const struct tm *tm_p);

asctime converts a time specification coded in accordance with the structure tm (see
below) into a string. No check is made here to see whether the time specification is
meaningful, i.e. whether, for instance, the specified number of days fits the specified month.
An error exists only when the data entered cannot be displayed in the time format.
Consequently the earliest possible date which can be displayed is -999, and the latest date which
can be displayed is 9999.

Parameters  const struct tm *tm_p Structure as in the include file <time.h>:

struct tm
{
       int   tm_sec;        /* seconds (0-59) */
       int   tm_min;        /* minutes (0-59) */
       int   tm_hour;       /* hours  (0-23) */
       int   tm_mday;       /* day of the month (1-31) */
       int   tm_mon;        /* month from start of year (0-11) */
       int   tm_year;       /* years since 1900 */
       int   tm_wday;       /* weekday (0-6, Sunday=0) */
       int   tm_yday;       /* day since January 1 (0-365) */
       int   tm_isdst;      /* daylight saving time flag */
};

Return val.

Pointer to the string generated.

The resulting string has a length of 26 (including the null byte) and is
formatted as a date and time specification:
Weekday Month Day Hrs:Min:Sec Year,
e.g. Fri Apr 29 12:01:20 2011\n\0

NULL

In the event of an error

Notes

The asctime, ctime, ctime64, gmtime, gmtime64, localtime and localtime64
functions write their result into the same internal C data area. This means that each of these
function calls overwrites the previous result of any of the other functions.

A structure of type tm is returned as the result by the gmtime, gmtime64, localtime and
localtime64 functions.

The calls asctime(localtime(sec_p)) and ctime(sec_p) are equivalent. In the same
way the calls asctime(localtime64(sec_p)) and ctime64(sec_p) are equivalent.

Example

#include <time.h>

#include <stdio.h>

struct tm *t;

char *s;

time_t clk;

int main(void)

{

   clk = time((time_t *) 0);

   t = gmtime(&clk);

   printf("Year: %d\n", t->tm_year + 1900);

   printf("Time in hours: %d\n", t->tm_hour);
   printf("Day of the year: %d\n", t->tm_yday);

   s = asctime(t);

   printf("%s", s);

   return 0;

}

See also

ctime, ctime64, gmtime, gmtime64, localtime, localtime64, mktime, mktime64, time, time64