I am using RED HAT machine. I suppose to get system time in my program.below is a part of a code.
date=%Y-%m-%d time=%H:%M:%S
is the format I wants.
issue is it is giving me GMT time instead of my current system time.
how can I get system time
in this format?
char *buf_cur = buf;
char timestr[TIMEBUF_SIZE];
time_t now = time (0);
strftime(timestr,TIMEBUF_SIZE, "date=%Y-%m-%d time=%H:%M:%S", localtime(&now));
buf_cur += sprintf(buf_cur, "%s",timestr);
in short I want a time which "date" command gives in linux. with above format.
The
localtime()
function converts the calendar time timep to broken- down time representation, expressed relative to the user's specifiedtimezone
i.e.GMT
To get time in
UTC
, you should usegmtime()
.