注册 登录
编程论坛 C++教室

C中怎样调用系统时间

为了学好C 发布于 2010-08-17 11:19, 1179 次点击
比如现在时间:
早上:08:07:06
下午:15:15:15
晚上:21:21:21
5 回复
#2
hahayezhe2010-08-17 11:54
CTime t = CTime::GetCurrentTime();

atltime.h
#3
x884845322010-08-17 12:52
不错,学习了
#4
ciweitou1632010-08-17 13:05
结合C++ reference,不知道是否需要。
程序代码:
#include <ctime>
#include <iostream>

using namespace std;

int main()
{
    char * timeTemp;
    time_t theTime;
    time( &theTime );   // get the calendar time
    tm *t = localtime( &theTime );  // convert to local
    cout << "The time is: " << asctime(t);
    strncpy(timeTemp,(asctime(t))+11,8);    //只获取时间部分
    cout<<timeTemp<<endl;
    return 0;
}
#5
pangding2010-08-18 01:06
嗯,就和 C 一样,用 ctime 的那老一套方法就行。关于时间这方面,C++ 的标准库没做什么特别的扩展。
#6
为了学好C2010-08-19 09:05
谢谢!!!
1