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));
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster