C++时间标准库时间time
转自:http://www.cnblogs.com/yukaizhao/archive/2011/04/29/cpp_time_system_time.html (玉开)
C++标准库中的时间需要引用time.h,可以取的本地时间或者格林威治时间,只能精确到秒
#include <iostream> /*包含time头文件*/
#include <time.h> using namespace std; int main()
{
//time_t是long类型,精确到秒,是当前时间和1970年1月1日零点时间的差
const time_t t = time(NULL); cout<<"current time is "<<t<<endl; /*本地时间:日期,时间 年月日,星期,时分秒*/
struct tm* current_time = localtime(&t);
printf("current year is %d;current month is %d;current date of month is %d\r\n",
1900 + current_time->tm_year,
1 + current_time->tm_mon/*此month的范围为0-11*/,
current_time->tm_mday); printf("current day of year is %d;current day in week is %d\r\n",
current_time->tm_yday,/*当前日期是今年的第多少天[0,365] */
current_time->tm_wday/*days since Sunday - [0,6] */); printf("time part %d:%d:%d \r\n",
current_time->tm_hour,
current_time->tm_min,
current_time->tm_sec); printf("\t本地时间:%d-%d-%d %d:%d:%d\r\n",
current_time->tm_year + 1900,
current_time->tm_mon + 1,
current_time->tm_mday,
current_time->tm_hour,
current_time->tm_min,
current_time->tm_sec); /*格林威治时间*/
struct tm* current_gmtime = gmtime(&t); printf("格林威治时间:%d-%d-%d %d:%d:%d\r\n",
current_gmtime->tm_year + 1900,
current_gmtime->tm_mon + 1,
current_gmtime->tm_mday,
current_gmtime->tm_hour,
current_gmtime->tm_min,
current_gmtime->tm_sec); system("pause");
return 0;
}
C++时间标准库时间time的更多相关文章
- C++时间标准库时间time和系统时间的使用
#include <iostream> #include <time.h> #include <stdio.h> #include <windows.h> ...
- C语言日期时间标准库
用思维导图整理: 代码: #include <stdio.h> #include <time.h> #include <string.h> int main() { ...
- C语言-12-日期和时间处理标准库详细解析及示例
概述 标准库 提供了用于日期和时间处理的结构和函数 是C++语言日期和时间处理的基础 与时间相关的类型 clock_t,本质是:unsigned long typedef unsigned long ...
- 【python标准库模块一】时间模块time学习
本文介绍python的标准库模块time的常见用法 时间模块time 导入时间模块 import time 得到时间戳,这是统计从1970年1月1日0点0分到现在经过了多少秒,一般用于加减法一起用,比 ...
- [C/C++标准库]_[初级]_[转换UTC时间到local本地时间]
场景 1.如果有面向全球用户的网站, 一般在存储时间数据时存储的是UTC格式的时间, 这样时间是统一的, 并可以根据当地时区来进行准确的转换. 2.存储本地时间的问题就在于如果换了时区, 那么显示的时 ...
- 5.Python3标准库-日期和时间
''' 不同于int,str,float,Python没有包含对应日期和时间的原生类型,不过提供了3个相应的模块,可以采用多种表示来管理日期和时间值 time模块由底层C库提供与时间相关的函数.它包含 ...
- python_81_标准库_时间模块
''' 标准库: 1.time 时间的三种表示方法:a:时间戳(timestamp) b:格式化的时间字符串 c:元组(struct_time)共九个元素 time.struct_time(tm_ye ...
- python中时间处理标准库DateTime加强版库:pendulum
DateTime 的时区问题 Python的datetime可以处理2种类型的时间,分别为offset-naive和offset-aware.前者是指没有包含时区信息的时间,后者是指包含时区信息的时间 ...
- python常用标准库(时间模块 time和datetime)
常用的标准库 time时间模块 import time time -- 获取本地时间戳 时间戳又被称之为是Unix时间戳,原本是在Unix系统中的计时工具. 它的含义是从1970年1月1日(UTC/G ...
随机推荐
- C# 文本转语音朗读
1. 利用DONET框架自带的 SpeechSynthesizer ,缺点是没有感情色彩,抑扬顿挫等. using System; using System.Collections.Generic; ...
- EJB开发第二期---开发具有本地接口的无状态Bean
一.EJB中的bean 1.1 EJB中bean分类 会话bean(session bean) 负责与客户端交互,是编写业务逻辑的地方,在会话bean中可以通过jdbc直接操作数据库,但大多数情况下都 ...
- 解决:Linux SSH Secure Shell(ssh) 超时断开的解决方法
转载:http://www.cnblogs.com/jifeng/archive/2011/06/25/2090118.html 修改/etc/ssh/sshd_config文件,找到 ClientA ...
- Css_*^$
#search_condition [class*=search_submit] 表示class name里面的值包含search_submit $("#search_condition [ ...
- Unity光照与渲染设置学习笔记
学习了一下unity中有关光照和渲染的一些设置,现在才明白之前遇到的一些问题只是没有正确设置而已. unity不同版本的光照设置会有一些差异,而且可以调节的参数非常多,这里只记录一些重要的参数和使用方 ...
- Unity---Inspector面板自定义
一. 参数自定义 一个含有成员的类Player using System.Collections; using System.Collections.Generic; using UnityEngin ...
- 区块链扩容方案之Gas值限制
区块链扩容一直是区块链团队的重点研究方向.因为比特币对区块大小的设定是固定的,而且中本聪将最初大小值限定为1M,但随着交易量的增加,网络拥堵情况也愈渐严重,最终也导致了比特币的分叉. 区别于比特币固定 ...
- npm安装时一些错误
1. npm install 提示no such file or directory 缺少package.json 首先初始化, npm init -f 然后安装依赖 npm install form ...
- sql not in 优化问题
问题情境: not in 耗时过长.想用join或exits代替.结果并不明显,这里先记录3种写法,以后探讨速度问题. sql语句: // not exists sql = @"select ...
- 第二个Spring冲刺周期团队进展报告
第一天:找识别不了的原因 第二天:继续找识别不了的原因 第三天:找文字库,找到tessdata语言包,放到手机SD卡根目录 第四天:了解OCR引擎 第五天:将导入tess-two导入到项目中,并进行测 ...