目录
说明
使用vs code配置了minGW-w64
使用了两种方法获取时间:
- 第一种是C的time,只能显示到秒,输出也要自己进行处理(要输出真实的日期,需要tm_year+1900, tm_mon+1)
- 第二种使用STL,显示到更小的位数(不足之处是没有好的时间格式化方法,不能方便的输出,所以一般是先转为time_t,C的方式来输出)
- 注意加入相应的头文件
代码
//共用
#include<iostream>
#include<string>
//getTimeOne()
#include<time.h>
#include <sstream>
//getTimeTwo()
#include<chrono>
using namespace std;
void getTimeOne();
void getTimeTwo();
int main()
{
getTimeOne();
getTimeTwo();
return 0;
}
void getTimeOne()
{
time_t now1 = time(NULL);
tm* tm_t = localtime(&now1);
stringstream ss;
ss<< tm