Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>asctime() convert time from structure to string</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 asctime()               Convert Time from Structure to String

 #include   <time.h>

 char       *asctime(time);           Pointer to the time, as string
 const struct tm *time;         Pointer to struct defined in <time.h>

    asctime() converts a date and time stored as a structure into a
    string of 26 characters in the form:

     Sun Dec 27 02:30:00 1984\n\0

 Field widths are constant, and the new-line character ('\n') and the
                null character ('\0') occupy the last two positions of
                the string.

    The time structure is available through the function gmtime() or
    localtime().

       Returns:     A pointer to the resulting character string.  There
                    is no error return.


         Notes:     Both gmtime() and localtime() return a pointer to the
                    'tm' structure. 'tm' is defined in <time.h> as:

                  'tm_sec'  :      Seconds (0-59)
                  'tm_min'  :      Minutes (0-59)
                  'tm_hour' :      Hours (0-23)
                  'tm_mday' :      Day of month (1-31)
                  'tm_mon'  :      Month (0-11; Jan = 0)
                  'tm_year' :      Year (current year minus 1900)
                  'tm_wday' :      Day of the week (0-6; Sun = 0)
                  'tm_yday' :      Day of the year (0-365; Jan 1 = 0)
                  'tm_isdst':      Non-zero if daylight saving time, zero
                                   if standard time.

                    asctime() writes its string into a static buffer that
                    will be overwritten by another call to either
                    asctime() or ctime().

   -------------------------------- Example ---------------------------------

    The following statements get the time stored as a long integer, store
    it in a structure, convert the structure to a character string, and
    print it out.

           #include <time.h>
           #include <stdio.h>

           long elapsetime;
           struct tm  *greentime;

           main()
           {
               time(&elapsetime);               /* Get time in seconds  */
               greentime = gmtime(&elapsetime); /* Convert to structure */
               printf("Greenwich time is %s\n",asctime(greentime));
           }



See Also: gmtime() ctime() localtime() time()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson