您的位置:首页 > 编程语言 > C语言/C++

OCCI 获取系统时间函数 C++

2012-09-25 14:27 405 查看
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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: