0 votes
111 views
in C programming by (98.9k points)
edited
C Program to Print Current Date and Time

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
#include <time.h>
#include <stdio.h>
#include <conio.h>
  
int main(void)
{
    time_t current_time;
    char* c_time_string;
  
    current_time = time(NULL);
  
    if (current_time == ((time_t)-1))
    {
        printf("Error in computing current time.");
        return 1;
    }
  
     c_time_string = ctime(&current_time);
  
    if (NULL == c_time_string)
    {
        printf("Error in conversion of current time.");
        return 1;
    }
  
     printf("Current time is %s", c_time_string);
    getch();
    return 0;
}

 

Related questions

0 votes
1 answer 105 views
0 votes
1 answer 104 views
asked Jul 20, 2022 in C programming by Doubtly (98.9k points)
0 votes
1 answer 101 views
asked Jul 20, 2022 in C programming by Doubtly (98.9k points)
0 votes
1 answer 396 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

535 users

...