HP 3000 Manuals

asctime [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Library Reference Manual

asctime 

Converts a tm structured time variable into a null-terminated
26-character string.

Syntax 

     #include <time.h>
     char *asctime (const struct tm *timeptr);

Parameters 

timeptr       A pointer to a structure of type tm that contains the
              broken-down time.

Return Values 

x             A pointer to the string.

Description 

The asctime function provides a way for you to get the current time,
modify it in some way, and then print the result in ASCII form.

The timeptr parameter points to a structure of type tm whose members were
assigned values with localtime(), gmtime(), or explicitly by you.  The
asctime function returns a character pointer to a null terminated string
with a maximum length of 26 characters.  This string is the same type as
the string returned by ctime().  Because asctime() returns a pointer to a
static character array, it is overwritten by subsequent calls to
asctime().

Example 

The date command shown in the section on ctime() can be rewritten using
localtime() and asctime():

        #include <stdio.h>
        #include <time.h>
        main()
        {
           int time(), nseconds;
           struct tm *ptr, *localtime();
           char *string, *asctime();

           nseconds = time(NULL);
           ptr = localtime(&nseconds);

     /* you may modify the current time in tm here */

           string = asctime(ptr);
           printf("%s", string);
        }

This program illustrates an indirect way to obtain the date, but it does
enable you to modify the date stored in tm before you print the data.  If
you only want to print the date, use the time/ctime combination.

Of all the ctime functions, the localtime function is the most useful.
The localtime function enables you to break up the current time into
chunks that can be easily referenced and examined for such applications
as personal calendar programs and program schedulers.  Many of the tm
values can be used as indices into arrays containing strings identifying
months and days.  For example, declaring an external array like

        char *month[ ] = { "January", "February", "March", "April",
                          "May", "June", "July", "August", "September",
                          "October", "November", "December"
                        };

enables you to use tm_mon as an index into this array to obtain the
actual month name.  The same thing can be done with tm_wday if you
initialize an array containing the names of the days of the week.

See Also 

clock(), mktime(), localtime(), time(), ANSI C 4.12.3.1, POSIX.1 8.1.1



MPE/iX 5.0 Documentation