在记录程序日志时, 需要记录时间. 如下:
- #include <iostream>
- #include <time.h>
- #include <windows.h>
- using namespace std;
- int main() {
- time_t t = time(0);
- char tmp[64];
- strftime(tmp, sizeof(tmp), "%Y/%m/%d %X %A %j %z", localtime(&t));
- cout << tmp << endl;
- system("pause");
- return 0;
- }
即 Y 为年, m 为月, d 为日, X 为具体时分秒, A 为星期, j 为天数, z 为其他, 结果如下:
2018/06/04 19:52:54 Monday 155 China Standard Time
来源: http://www.bubuko.com/infodetail-2630976.html