C++程序中如何獲取系統時間
1、系統時間即本地時間;
2、時間是指年、月、日、時、分、秒以及星期;
3、程序代碼如下:
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{SYSTEMTIME st;//定義本地時間變量,該變量為結構體
GetLocalTime(&st);//獲取本地時間函數,參數為時間變量指針
cout<<“年:”<<st.wYear<<endl;//顯示某年
cout<<“月:”<<st.wMonth<<endl;//顯示某月
cout<<“日:”<<st.wDay<<endl;//顯示某日
cout<<“時:”<<st.wHour<<endl;//顯示某時
cout<<“分:”<<st.wMinute<<endl;//顯示某分
cout<<“秒:”<<st.wSecond<<endl;//顯示某秒
cout<<“星期:”<<st.wDayOfWeek<<endl;//顯示星期
return 0;
}
4、程序編輯窗口如下:

5、程序運行窗口如下:

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/225542.html
微信掃一掃
支付寶掃一掃