我正在使用红帽机器。我想在我的程序中获取系统时间。下面是代码的一部分。
date=%Y-%m-%d time=%H:%M:%S
是我想要的格式。问题是它给了我格林威治标准时间而不是我当前的系统时间。我怎样才能得到system time
这种格式?
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);
简而言之,我想要一个“日期”命令在 linux 中给出的时间。与上述格式。