Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>ctime() convert time from long integer to string</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
ctime()                  Convert Time from Long Integer to String

 #include   <time.h>                     Required for declarations only

 char       *ctime(time);                Pointer to character string
 long       *time;                       Pointer to stored time

    ctime() converts a time, stored as a long value, to a character
    string.  'time' can be obtained from a call to time().  time() returns
    the number of seconds elapsed since 00:00:00 Greenwich mean time,
    January 1, 1970.

    ctime() produces a 26-character string that has the following form:

                      Sun Dec 21 04:45:00 1986\n\0

    All fields have a constant width.  The new-line character ('\n') and
    the null character ('\0') occupy the last two positions in the string.

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

      Notes:    Under MS-DOS, dates prior to 1980 are not recognized.  If
                'time' represents a date before Jan 1, 1980, ctime()
                returns the date Jan 1, 1980.

                A 24-hour clock is used.

                ctime() and asctime() use a single statically allocated
                buffer for holding the return string.  A call of either
                routine will destroy the result of any previous call.

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

    The following statements get the number of seconds elapsed since
    1/1/70, convert it to the corresponding date and time in string
    format, and print the resulting string.

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

         long elapstime;

         main()
         {
             time(&elapstime);
             printf("Number of seconds since 1-1-70: %ld \n",elapstime);
             printf("That means the current date & time is: %s \n",
                   ctime(&elapstime));
         }

See Also: asctime() ftime() gmtime() localtime() time()

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