Ctime
lastmod 2021-02-21created 2015-05-096 edits
Simple example
Printing the current time
#include <stdio.h>
#include <time.h>
int main(void){
time_t t = time(NULL);
struct tm tm = *localtime(&t);
printf("now: %d-%d-%d %d:%d:%d\n",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
return 0;
}
See also
Favorite site
- How to get current time and date in C++?
- Getting the current date and time (2) - localtime_s (VC 2005 or later)
- Function to get the current date/time/year-month-day, hour-minute-second (today's date and time): Current Date, Time
- TimeStamp to DateTime: converting time in seconds and printing it (convert timeStamp to DateTime String)