//time.t下的函数.
#include <iostream>
#include <time.h>
#include <windows.h>
#include <vector>
using namespace std;
#pragma warning(disable:4996)//重要函数.
/*
1.time_t time(0); //返回的是从1970.1.1凌晨0点到当前时间的秒数.
2.tm* localtime(time_t*); //把秒数转化为具体的时间.tm是一个结构体.具体成员可以右键,然后转到定义~
3.double difftime(time_t t1, time_t t2); //比较两个time_t对象的差异.也就是相差的秒数.
4.char* ctime(const time_t*); //把time_t对象转化为一段字符串.
5.time_t mktime(struct tm* ); //把一个具体时间转化为一个秒数.
6.clock_t clock(); //相当于一个时钟,两个clock_t对象的差值,代表间隔的时间,单位是毫秒,更精确了.*/int main()
{//第一个例子:time_t s = time(0); //time(0)返回的是从1970.1.1凌晨0点到当前时间的秒数,它是一个一直在变化的值.cout << s << endl;//第二个例子:/*tm *temp = localtime(&s);int hour = temp->tm_hour; //几点.int minute = temp->tm_min; //几分.int month = temp->tm_mon; //几月int week = temp->tm_wday; //周几.0代表周日.int year = temp->tm_year + 1900; //几年.int second = temp->tm_sec; //几秒.int day = temp->tm_mday; //几天.cout << year << "/" << month << "/" << day << "/" << hour << ":" << minute << ":" << second << " " << "星期" << week << endl;cout << __DATE__ << " " << __TIME__ << endl; //当然关于时间,也可以用C语言的宏来体现.同样非常的快.*///第三个例子:/*time_t s = time(0);//间隔3000毫秒.Sleep(3000);time_t temp = time(0);cout << difftime(temp, s) << endl;*///第四个例子:/*time_t s = time(0);//把秒数转换为字符串.char *q = ctime(&s);cout << q << endl;*///第五个例子:/*clock_t temp = clock();vector<int> w;for (int i = 0; i < 1000000; ++i){w.push_back(i);}clock_t s = clock();//两个时钟之差为间隔的时间.单位是毫秒!!!cout << s - temp << endl;*/system("pause");return 0;
}
详细解决方案
ANSI C标准库: time.h下函数讲解
热度:114 发布时间:2023-10-30 20:25:22.0
相关解决方案
- 数据库 connect time out解决方案
- https下session time out后,无法再次登陆,该如何处理
- 怎么设置TextBox编码为“ANSI”
- !odac140.bpl it is not design time package
- silverlight socket 怎么支持 ansi 和 gb2312编码
- update voter set time=#2007/04/28# 14:04:44# where id=1 错在哪了 请大哥指点,该如何解决
- 非常非常急敬请高手们帮忙!分在前两天都散光了!DB2数据库连接出现 SQL0666-Estimated query processing time 192 exceeds limit 30,该如何解决
- oracle数据库施行update语句时弹出Execution time
- 急等解决报错:Run-time error '1004'. Application-defined or operation-defined error,该如何处理
- ! CDMA时间戳(Time Stamp)
- 求救! CDMA时间戳(Time Stamp)!解决办法
- time() 函数取的哪个系统的时间?解决办法
- time() 函数取的哪个系统的时间?解决思路
- fastdb "group by time"查询一组时间,该怎么处理
- vfp date and time picker控件有关问题
- sorry,long time no see.该如何解决
- 0928I wish I had all the time I'd ever wasted,so I could waste it all over again解决方法
- 每日背熟一句英语(11)I spent most of my spare time reviwing those sentences last weekend
- 每日背熟一句英语(5)By the time he got back to his coffee it was stone-cold
- 每天背熟一句英语(5)By the time he got back to his coffee it was stone-cold.解决办法
- 每天背熟一句英语(11)I spent most of my spare time reviwing those sentences last weekend.解决思路
- sorry,long time no see.解决方法
- 英文小说推荐-The Curious Incident of the Dog in the Night-Time,该如何处理
- SVN运用的一些注意事项(upgrade over time)
- "stdlib.h","math.h"和"time.h"
- “ANSI trigraph 特性”这是什么特性?
- AspectJ 编译时织进(Compile Time Weaving, CTW)
- 关于在asp中调用microsoft date and time picker组件显示日期的有关问题
- java 时间戳跟PHP时间戳 的转换 php time()
- Maximum execution time of 30 seconds exceeded