关于时间的问题

tuantuanlee 2006-11-26 02:22:56
能返回操作系统当前时间的库函数是哪一个呀,还有就是时间是什么数据类型呢?例如:14:21是个什么数类型。
...全文
176 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ReverseEngineering 2006-12-24
  • 打赏
  • 举报
回复
得到的是串类型吧?
cruzeflute 2006-11-27
  • 打赏
  • 举报
回复
#include<time.h>
也可以改成
#include<ctime>
cruzeflute 2006-11-27
  • 打赏
  • 举报
回复
#include<iostream>
#include<time.h>
#include<cstdlib>
using namespace std;

int main()
{
tm *local;
time_t t;


t=time(NULL);
local = localtime(&t);//得到本地时间,是个结构
/*struct tm {
int tm_sec; // seconds after the minute - [0,59]
int tm_min; // minutes after the hour - [0,59]
int tm_hour; // hours since midnight - [0,23]
int tm_mday; // day of the month - [1,31]
int tm_mon; // months since January - [0,11]
int tm_year; // years since 1900
int tm_wday; // days since Sunday - [0,6]
int tm_yday; // days since January 1 - [0,365]
int tm_isdst; // daylight savings time flag
};
*/
cout<<ctime(&t)<<endl;//打出本地时间
cout<<local->tm_mon+1<<"/"
<<local->tm_mday<<"/"
<<local->tm_year+1900<<" "
<<local->tm_hour<<":"
<<local->tm_min<<":"
<<local->tm_sec<<endl;
system("pause");
return 0;
}
liurenbin13 2006-11-27
  • 打赏
  • 举报
回复
MFC得到当前时间的函数是GetCurrentTime();
类型是CTime类型
arrowcy 2006-11-27
  • 打赏
  • 举报
回复
时间是long型的,用time可以获取,但使用什么函数转换成字符串我不记得了

33,319

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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