时间函数

tracy07056 2008-11-03 12:45:57
取计算机当前时间的函数怎么写啊,要求能在主函数里调用这个时间值
...全文
57 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
C标准库函数localtime();

#include <stdio.h>
using namespace std;
#include <time.h>
int main(void)
{
time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t) );
puts( tmp );
return 0;
}//main()
mo229mo 2008-11-03
  • 打赏
  • 举报
回复
#include <iostream>
#include <time.h>
using namespace std;

class CGetTime
{
time_t m_timenow;
struct tm *m_pLocatime;
char *m_strTime;
public:
CGetTime();
void Display();

};

CGetTime::CGetTime()
{
time(&m_timenow);
m_pLocatime=localtime(&m_timenow);
m_strTime=asctime(m_pLocatime);
}
void CGetTime::Display()
{
cout<<m_strTime;
}
int main()
{
CGetTime myTime;
cout<<"Now Time is: "<<endl;
myTime.Display();

}

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧