C Tutorial
This
C Program to get current system current date and time using localtime function.#include<stdio.h> #include<time.h> void main() { time_t t = time(NULL); struct tm time = *localtime(&t); printf("date - %d:%d:%d\n", time.tm_mday, time.tm_mon + 1, time.tm_year + 1900); printf("time- %d:%d %d\n", time.tm_hour, time.tm_min, time.tm_sec); }Output:
$ cc system-time.c $ ./a.out date - 12:3:2018 time- 21:51 50
This c program is to get the system current date and time as string using ctime function.
#include<stdio.h> #include<time.h> void main() { char* time_now; time_t t = time(NULL); time_now = ctime(&t); printf("date and time now: %s", time_now); }Output:
$ cc system-time.c $ ./a.out current time: Tue Mar 12 22:00:56 2018
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page