【发布时间】:2013-12-04 06:41:10
【问题描述】:
我正在使用 RED HAT 机器。我想在我的程序中获取系统时间。下面是代码的一部分。
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 中给出的时间。以上格式。
【问题讨论】:
-
根据this 应该考虑时区。
标签: c time systemtime