Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: How do I write code to retrieve current date and time from the system and display it as a string?

Answer: Use time( ) function to get current date and time and then ctime( ) function to display it as a string. This is shown in following code snippet.

#include <systypes.h>

void main( )
{
time_t curtime ;
char ctm[50] ;

time ( &curtime ) ; //retrieves current time &
stores in curtime
printf ( "nCurrent Date & Time: %s", ctime (
&curtime ) ) ;
}

Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook