转自: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的更多相关文章

  1. C++时间标准库时间time和系统时间的使用

    #include <iostream> #include <time.h> #include <stdio.h> #include <windows.h> ...

  2. C语言日期时间标准库

    用思维导图整理: 代码: #include <stdio.h> #include <time.h> #include <string.h> int main() { ...

  3. C语言-12-日期和时间处理标准库详细解析及示例

    概述 标准库 提供了用于日期和时间处理的结构和函数 是C++语言日期和时间处理的基础 与时间相关的类型 clock_t,本质是:unsigned long typedef unsigned long ...

  4. 【python标准库模块一】时间模块time学习

    本文介绍python的标准库模块time的常见用法 时间模块time 导入时间模块 import time 得到时间戳,这是统计从1970年1月1日0点0分到现在经过了多少秒,一般用于加减法一起用,比 ...

  5. [C/C++标准库]_[初级]_[转换UTC时间到local本地时间]

    场景 1.如果有面向全球用户的网站, 一般在存储时间数据时存储的是UTC格式的时间, 这样时间是统一的, 并可以根据当地时区来进行准确的转换. 2.存储本地时间的问题就在于如果换了时区, 那么显示的时 ...

  6. 5.Python3标准库-日期和时间

    ''' 不同于int,str,float,Python没有包含对应日期和时间的原生类型,不过提供了3个相应的模块,可以采用多种表示来管理日期和时间值 time模块由底层C库提供与时间相关的函数.它包含 ...

  7. python_81_标准库_时间模块

    ''' 标准库: 1.time 时间的三种表示方法:a:时间戳(timestamp) b:格式化的时间字符串 c:元组(struct_time)共九个元素 time.struct_time(tm_ye ...

  8. python中时间处理标准库DateTime加强版库:pendulum

    DateTime 的时区问题 Python的datetime可以处理2种类型的时间,分别为offset-naive和offset-aware.前者是指没有包含时区信息的时间,后者是指包含时区信息的时间 ...

  9. python常用标准库(时间模块 time和datetime)

    常用的标准库 time时间模块 import time time -- 获取本地时间戳 时间戳又被称之为是Unix时间戳,原本是在Unix系统中的计时工具. 它的含义是从1970年1月1日(UTC/G ...

随机推荐

  1. 20155306 白皎 0day漏洞——漏洞的复现

    一.Ubuntu16.04 (CVE-2017-16995) 1.漏洞概述 Ubuntu最新版本16.04存在本地提权漏洞,该漏洞存在于Linux内核带有的eBPF bpf(2)系统调用中,当用户提供 ...

  2. C++自学成长之路(第一篇)

    今天开始我将开启C++自学成长之路,今天是第一天,在以前就一直在网上查找关于c++的资料,想买一本好一点的,权威一点的资料书,通过努力查找,我选择了c++ primer,在网上这本书的好评如潮.更多的 ...

  3. noi.ac 257 B

    链接 题目 区间[l,r]是连续满足,[l,r]中的数字的权值区间是一段连续的.多次询问可以完包含一个区间的连续区间.区间长度尽量小,如果有多个输出左端点靠左的. 分析: [l,r]区间是连续的,当且 ...

  4. HTML 中使 footer 始终处于页面底部

    通常在页面中,需要使页脚 footer 部分始终处于底部.当页面高度不够 100% 时, footer 处于页面最底部,当页面内容高于 100% 时,页脚元素可以被撑到最底部. 方法一:绝对定位 &l ...

  5. MySQL在x64系统上1067问题解决

    最近一个项目需要用到MYSQL,因为以前也弄过,所以就没怎么多想,直接下一个完事了.于是乎果断上官方网站下了一个installer(5.26),修改了一下默认位置和配置,然后一路next,最后在配置完 ...

  6. 微信小程序在当前页面设置其他页面的数据

    如果其他页面用到的数据是 globalData, 那么直接在当前页面修改 globalData 数据即可. 如果其他页面用到的数据是 storage, 那么直接在当前页面修改 storage 数据即可 ...

  7. linux systemctl 命令

    目录 预热 管理单个 unit 查看系统上的 unit 管理不同的操作环境(target unit) 检查 unit 之间的依赖性 相关的目录和文件 systemctl daemon-reload 子 ...

  8. 自动化部署-Jenkins+SVN+MSBuild 一些补充

    1.ftp的使用 系统管理->插件管理 安装插件Publish Over FTP 系统管理->系统设置 配置ftp参数 如下图 进入任务配置,添加构建后操作 在使用过程中还遇到一个本地防火 ...

  9. HDU Ignatius's puzzle

    链接 [http://acm.hdu.edu.cn/showproblem.php?pid=1098] 分析: 数学归纳法 f(1) = 18 + ka; 假设f(x) = 5x^13+13x^5+k ...

  10. alpha版发布

    网站网址:http://doeverying.applinzi.com/