【c】time.h
表示时间的三种类型
- 日历时间:从一个时间点到现在的秒数,用time_t表示
- 始终滴答时间:从进程启动到现在时钟的滴答数(每秒一般包含1000个)。用clock_t表示
- 分解时间:分解的数据结构如下。用tm表示
从计算机里获得时间的方法
- tim_t time(time_t *time),从某一时间到现在的秒数,一般问1970年1月1日午夜
- clock_t clock(void),从进程启动到现在累计的始终滴答数
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t times = time(NULL);
const clock_t clocks = clock();
cout << "times:" << times << endl;
cout << "clocks:" << clocks << endl; cout << "-------------------" << endl;
const time_t times2 = time(×);
cout << "times2:" << times2 << endl;
}
结果
三种时间转换函数
- struct tm* gmtime(const time_t* time)
- struct tm* localtime(const time_t* time)
- time_t mktime(struct tm* ptm)
时间日期数据个格式化输出
- char* asctime(const struct tm* tmptr) 周几 月份数 日数 小时数:分钟数:秒钟数 年份数
- char* ctime(const time_t* time) 周几 月份数 日数 小时数:分钟数:秒钟数 年份数
对时间的操作
double difftime(time_t time2, time_t time1)
案例
#include <iostream>
#include <ctime>
using namespace std; int main()
{
const time_t t = time(NULL);
cout << "second from (1970.01.01:00:00)" << t << endl;
tm* current_time = localtime(&t); cout << "year:" << + current_time->tm_year << endl;
cout << "month:" << + current_time->tm_mon << endl; cout << "=--------------=" << endl;
cout << "day of year:" << current_time->tm_yday << endl;
cout << "day of month:" << current_time->tm_mday << endl;
cout << "day of week:" << current_time->tm_wday << endl;
cout << "=--------------=" << endl; cout << "hour:" << current_time->tm_hour << endl;
cout << "minute:" << current_time->tm_min << endl;
cout << "second:" << current_time->tm_sec << endl;
cout << "------------" << endl;
cout << "time:" << ctime(&t) << endl;
cout << "time:" << asctime(current_time) << endl; }
结果
参考
time.h(维基)
【c】time.h的更多相关文章
- 【CodeForces】914 H. Ember and Storm's Tree Game 动态规划+排列组合
[题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsn ...
- 【一】 sched.h
第一个数据结构体是 task_struct ,这个数据结构被内核用来表示进程,包含其所有信息. 定义于文件 include/linux/sched.h 中,先看看其完整定义 struct task_s ...
- 【转】 jni.h头文件详解(二)
原文网址:http://blog.csdn.net/shaohuazuo/article/details/42932813 作者:左少华 博客:http://blog.csdn.net/shaohua ...
- 【转】stropts.h: No such file or directory – How to Fix
原文地址:stropts.h: No such file or directory – How to Fix 作者:xjc2694 It is a known issue that modern Li ...
- 【转载】limits.h
limits.h专门用于检测整型数据数据类型的表达值范围. <limits.h>主要提供对整型和字符型范围的限制的宏,同样没有指定类型和函数的定义. 1.整型宏如下表: 2.字符型宏如下表 ...
- 【图像处理】DVR H.264视频编码基本知识
视频编码技术基本是由ISO/IEC制定的MPEG-x和ITU-T制定的H.26x两大系列视频编码国际标准的推出.从H.261视频编码建议,到 H.262/3.MPEG-1/2/4等都有一个共同的不断追 ...
- 【操作说明】全能型H.265播放器如何使用?
本播放器集成了公司业务的接口,包含了实播,回放,云台控制和回放速度控制,截图和全屏功能可以根据type直接初始化接口地址如果是第三方业务对接,也可以单独配置接口地址 正确使用H.265播放器需要按以下 ...
- 【转载】OpenCV 摄像头控制
参考:[OpenCV] -- 简单摄像头操作 - 代码人生 - 博客频道 - CSDN.NET http://blog.csdn.net/qiurisuixiang/article/details/8 ...
- 伸展树的基本操作——以【NOI2004】郁闷的出纳员为例
前两天老师讲了伸展树……虽然一个月以前自己就一直在看平衡树这一部分的书籍,也仔细地研读过伸展树地操作代码,但是就是没写过程序……(大概也是在平衡树的复杂操作和长代码面前望而生畏了)但是今天借着老师布置 ...
随机推荐
- allegro生成光绘文件时,通过cam打开,*.drl钻孔文件不识别,为Unknow类型
生成钻孔文件时,NC_Parameters中,应该选Absolute
- 驱动makefile
1 ifeq ($(KERNELRELEASE),) 2 CURRENT_PATH=$(shell pwd) 3 #KERNEL_DIR:=/lib/modules/$(shell uname - ...
- Javascript Array.prototype.some()
当我们使用数组时,查找数组中包含某个特殊的项是非常常见的动作.下面例子是一个简单的实现: 01 planets = [ 02 "mercury", 03 " ...
- Linux课本第一二章
一.第一章:Linux内核简介 1.操作系统和内核:操作系统是指在整个系统中负责完成最基本功能和系统管理的那些部分,包括内核.设备驱动程序.启动引导程序.命令行shall等. 内核就是操作系统的核心, ...
- Windows下将txt导入MySQL及远程连接设置
1.修改字符编码,全部修改为gbk.这样修改,重启后又会恢复默认值. show variables like '%char%'; set character_set_database=gbk; 其中, ...
- adb 选择设备
在adb中有多个设备时,可以先adb devices列举出设备,然后可以通过adb -s <设备名> [其他参数] 对某个设备进行操作. 例如: adb -s 0123456789ABC ...
- asp.net 中插入数据到access
这样报语法错误: insert into Menu_wx(userid,menutype,MenuID,menuname,MenuTitle,Url,Key,OrderValue,State) val ...
- 3223: Tyvj 1729 文艺平衡树 - BZOJ
Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 ...
- HDU 3974 Assign the task 暴力/线段树
题目链接: 题目 Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 【POJ】【2096】Collecting Bugs
概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...