C++获取系统时间
2018-07-20 来源:open-open
- //由于使用了windows.h,所以这种方法只能在windows系统下使用,不能在Mac或linux下使用
#include "iostream"
#include "windows.h"
#include "string"
using namespace std;
int main(){
SYSTEMTIME ct;
GetLocalTime(&ct);;//如果用GetSystemTime(&ct),则获取的是格林尼治时间
int year = ct.wYear;
int month = ct.wMonth;
int day = ct.wDay;
int hour = ct.wHour;
int minute = ct.wMinute;
int second = ct.wSecond;
cout << year << "/" << month << "/" << day << " "
<< hour << ":" << minute << ":" << second << endl;
//把时间转换成字符串
char tmp[100];
sprintf_s(tmp, "%d/%d/%d %d:%d:%d", year, month, day, hour, minute, second);
string s = tmp;
cout << s << endl;
cout << tmp << endl;
return 0;
}
标签: linux
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:动态规划走楼梯
下一篇:迪杰斯特拉算法求最短路径
最新资讯
热门推荐