C : Implementation of ctime()
Hello, I am the student of the MCA first year. I had learn the C language in the BscIT. I know about some of the header files of the C language. So, I want to know about the ctime() function. I also want to know about the what is actual use of the ctime() function, How ctime() function works, and How can I implement the ctime() function in the C language. If anyone has the any idea about the ctime() function, so Please reply me.
Implementation of ctime()
Hi, The calendar time that is pointed to by timer to the local time can be converted by the ctime() function basically in the form of string consisting of 26 characters exactly. Example of this string can be shown in form of the following :
Sun Feb 22 15:58:27 1988\n\0
The syntax of the ctime() function can be as follows :
#include <time.h>
char *_ctime( const time_t *timer, char *buf );
Re: C : Implementation of ctime()
I guess you should understood from the following explanation. If the ctime() function is an ANSI function then it places the resultant string in a static buffer that can be used again every time whenever the ctime() function can be called. If the ctime() function is an NON-ANSI function then it places the resultant string in the buffer that can be pointed to by buf. The tzset() function can also be called whenever the ctime() function is being called.
C : Implementation of ctime()
The following sample program helps you to understand ctime() function more easily :
#include <stdio.h>
#include <time.h>
void main()
{
time_t timfdy;
char bf[26];
timfdy = time( NULL );
printf( " It is now: %s ",
ctime( &timfdy, bf ) );
}
The output of the above program can be :
It is now: Sat jan 25 15:58:42 1988
Re: C : Implementation of ctime()
By using the time() function the calender time can be obtained. That calender time can be generally Co-ordinated Universal Time. This UTC can be known as the GMT that means Greenwich Mean Time. The time set on the computer with the QNX date command reflects Coordinated Universal Time. The environment variable that is TZ can be used to established the local time zone.