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,894 questions

51,825 answers

573 users

How to print the OS date & time in C

1 Answer

0 votes
#include <stdio.h>
#include <time.h>
 
int main(void)
{
    time_t current_time;
    char *time_string, s[30];
    struct tm *tm_info;
 
    // print date time exampe 1
    current_time = time(NULL); // time as seconds
    time_string = ctime(&current_time); // Convert current_time to date-time format
    printf("%s\n", time_string);
    
    // print date time example 2
    time(&current_time);
    tm_info = localtime(&current_time);
    strftime(s, 30, "%Y:%m:%d - %H:%M:%S", tm_info);
    printf("%s\n", s);
    
    return 0;
}


answered Sep 7, 2014 by avibootz

Related questions

...