COHERENT manpages

This page displays the COHERENT manpage for asctime() [Convert time structure to ASCII string].

List of available manpages
Index


asctime() -- Time Function (libc)

Convert time structure to ASCII string
#include <time.h>
#include <sys/types.h>
char *asctime(tmp)
struct tm *tmp;

asctime() takes the  data found in tmp, and turns  it into an ASCII string.
tmp is  of the  type tm, which  is a structure  defined in the  header file
time.h.  This structure  must first  be initialized  by either  gmtime() or
localtime() before it can be used by asctime(). For a further discussion of
tm, see the entry for time.

asctime() returns a pointer to where it writes the text string it creates.

Example

The  following  example  demonstrates  the  functions  asctime(),  ctime(),
gmtime(),   localtime(),  and   time(),  and  shows   the  effect   of  the
environmental variable  TIMEZONE. For a discussion  of the variable time_t,
see the entry for time().

#include <time.h>
#include <sys/types.h>
main()
{
    time_t timenumber;
    struct tm *timestruct;

    /* read system time, print using ctime */
    time(&timenumber);
    printf("%s", ctime(&timenumber));

    /* use gmtime to fill tm, print with asctime */
    timestruct = gmtime(&timenumber);
    printf("%s", asctime(timestruct));

    /* use localtime to fill tm, print with asctime */
    timestruct = localtime(&timenumber);
    printf("%s", asctime(timestruct));
}

See Also

libc,
time(),
time [overview]
ANSI Standard, §7.12.3.1
POSIX Standard, §8.1.1

Notes

asctime() returns  a pointer  to a statically  allocated data area  that is
overwritten by successive calls.