#include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { //1.C++ 標準庫沒有提供所謂的日期類型。 C++ 繼承了C 語言用於日期和時間操作的結構和函數。 //為了使用日期和時間相關的函數和結構,需要在C++ 程序中引用 頭文件。 //有四個與時間相關的類型:clock_t、time_t、size_t 和tm。 //1.C++ time API: //https://www.cplusplus.com/reference/ctime/ //#include //有4類資料屬性 //(1)Functions:Time manipulation //(2)Conversion //(3)constants //(4)types (自訂資料型別) //例如:time_t:用來記錄秒數的時間,從1970/1/1,開始的秒數(int) //2. 取得現在時間 //(1)time_t time (time_t* timer) //取得一個 time_t 型別的值,代表現在的日期時間. //o time_t //一個整數代表經過的秒數,從 1970 年 1 月 1 日 00:00 UTC 起算。 //目的:取得目前日期時間的秒數: //(A).自訂資料型別:time_t = 目前的秒數 //(B).參數timer:this parameter can be a null pointer, in which case the parameter is not used (the function still returns a value of type time_t with the result) //指標一開始設定起始值,可以設定為NULL(全大寫,代表一個空指標) time_t t1 = time(NULL); cout<<"current seconds t1 = "<