Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to display current date and time in C

2 Answers

0 votes
#include <stdio.h>
#include <time.h>

int main(void) {
    time_t t = time(NULL);
    
    printf("%s", ctime(&t));
}




/*
run:

Sat Jun 26 06:52:42 2021

*/

 



answered Jun 26, 2021 by avibootz
0 votes
#include <stdio.h>
#include <time.h>

int main(void) {
    time_t t = time(NULL);
    
    struct tm lm = *localtime(&t);
    
    printf("%d-%02d-%02d %02d:%02d:%02d", lm.tm_mday, lm.tm_mon + 1, 
                                          lm.tm_year + 1900, lm.tm_hour, 
                                          lm.tm_min, lm.tm_sec);
}




/*
run:

26-06-2021 06:55:03

*/

 



answered Jun 26, 2021 by avibootz

Related questions

1 answer 137 views
1 answer 133 views
1 answer 116 views
1 answer 95 views
1 answer 130 views
1 answer 88 views
...