How to determine curreent date and time/

S

Sanchit

I am using GCC on FEDORA.

I want to print current date an time. How can do that.

Thanks
-Sanchit
 
A

aspinall

I am using GCC on FEDORA.

I want to print current date an time. How can do that.

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

int main(){

time_t now = time(NULL);
struct tm *now_s = localtime(&now);

if(now_s == NULL)
return EXIT_FAILURE;

printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+now_s->tm_year, ++now_s -
now_s->tm_mday, now_s->tm_hour, now_s->tm_min,now_s->tm_sec);

return EXIT_SUCCESS;
}

Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top