c++时间函数讲解

上传人:第*** 文档编号:32683296 上传时间:2018-02-12 格式:DOC 页数:6 大小:49.50KB
返回 下载 相关 举报
c++时间函数讲解_第1页
第1页 / 共6页
c++时间函数讲解_第2页
第2页 / 共6页
c++时间函数讲解_第3页
第3页 / 共6页
c++时间函数讲解_第4页
第4页 / 共6页
c++时间函数讲解_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《c++时间函数讲解》由会员分享,可在线阅读,更多相关《c++时间函数讲解(6页珍藏版)》请在金锄头文库上搜索。

1、C-C+时间函数的使用 一、获取日历时间time_t 是定义在 time.h 中的一个类型,表示一个日历时间,也就是从 1970 年 1 月 1日 0 时 0 分 0 秒到此时的秒数,原型是:typedef long time_t; /* time value */可以看出 time_t 其实是一个长整型,由于长整型能表示的数值有限,因此它能表示的最迟时间是 2038 年 1 月 18 日 19 时 14 分 07 秒。函数 time 可以获取当前日历时间时间,time 的定义:time_t time(time_t *)#include #include using namespace std

2、;int main(void)time_t nowtime;nowtime = time(NULL); /获取当前时间cout #include using namespace std;void dsptime(const struct tm *); /输出时间。int main(void)time_t nowtime;nowtime = time(NULL); /获取日历时间cout tm_year+1900 tm_mon+1 tm_mday tm_hour tm_min tm_sec tm_wday tm_yday #include using namespace std;int main

3、(void)time_t nowtime;nowtime = time(NULL); /获取日历时间cout #include using namespace std;int main(void)time_t start, ends;clock_t cstart,cends;start=time(NULL);cstart=clock();system(pause);ends=time(NULL);cends=clock();cout #include using namespace std;int main(void)time_t nowtime;nowtime = time(NULL); /获取日历时间cout nowtime endl; /输出 nowtimestruct tm *local;local=localtime( /获取当前系统时间char buf80;strftime(buf,80,格式化输出:%Y-%m-%d %H:%M:%S,local);cout buf endl;return 0;输出结果:1268575163格式化输出:2010-03-14 21:59:23

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 职业教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号