Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

10,484 questions

14,262 answers

573 users

How to get the current (now) date and time value in C

Winter Travel Deals
138 views
asked Jun 16, 2015 by avibootz
edited Jun 16, 2015 by avibootz

3 Answers

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

int main(int argc, char **argv) 
{ 
    time_t t = time(NULL);
    struct tm dt = *localtime(&t);
    
    printf("date time now: %d-%d-%d %d:%d:%d\n", dt.tm_year + 1900, 
                                                 dt.tm_mon + 1, 
                                                 dt.tm_mday, 
                                                 dt.tm_hour, 
                                                 dt.tm_min, 
                                                 dt.tm_sec);
    
    return(0);
}

/*
run:

date time now: 2015-6-16 9:54:49

*/

 




answered Jun 16, 2015 by avibootz
0 votes
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv) 
{ 
    time_t t = time(NULL);
    struct tm *dt = localtime(&t);
    char s_dt[50];
    
    strftime(s_dt, sizeof(s_dt), "%c", dt);
    printf("date time (now) = %s\n", s_dt);
    
    return(0);
}

/*
run:

date time (now) = 06/16/15 11:55:06

*/

 




answered Jun 16, 2015 by avibootz
0 votes
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv) 
{ 
    time_t t;
    struct tm *dt;
    time(&t);
    dt = localtime(&t);
    
    printf("date time now: %d-%d-%d %d:%d:%d\n", dt->tm_year + 1900, 
                                                 dt->tm_mon + 1, 
                                                 dt->tm_mday, 
                                                 dt->tm_hour, 
                                                 dt->tm_min, 
                                                 dt->tm_sec);
    
    return(0);
}

/*
run:

date time now: 2015-7-11 10:55:24

*/

 




answered Jul 11, 2015 by avibootz
...