OCCI 獲取系統時間函數 C++

OCCI

     Date current_date = Date::getSystemDate(environment_);

C++

需要包含

  #include<ctime>
      time_t t = time(NULL);
       tm* pt = localtime(&t);        

       Date current_date (environment_,(1900+pt->tm_year),pt->tm_mon,pt->tm_mday,pt->tm_hour,pt->tm_min,pt->tm_sec);     


例子:

// TestTime.cpp : 定義控制檯應用程序的入口點。
//

#include "stdafx.h"

#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>

using namespace std;

void showtime(tm* pt)
{
    cout<<setfill('0')<<1900 + pt->tm_year<<'-';
    cout<<setw(2)<<pt->tm_mon + 1<<'-';
    cout<<setw(2)<<pt->tm_mday<<' ';
    cout<<setw(2)<<pt->tm_hour<<':';
    cout<<setw(2)<<pt->tm_min<<':';
    cout<<setw(2)<<pt->tm_sec<<'\n';
}

int _tmain(int argc, _TCHAR* argv[])
{
     time_t t = time(NULL);
    tm* pt = localtime(&t);
    int sec = pt->tm_sec;
    showtime(pt);
    while(1)
    {
        t = time(NULL);
        pt = localtime(&t);
        if(sec != pt->tm_sec)
        {
            sec = pt->tm_sec;
            system("cls");
            showtime(pt);
        }
    }
    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章