转自: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. WPF Get jiayuan outbox list(send mail box)

      Request URL: http://www.jiayuan.com/msg/outbox/list.php Request Method: POST form data: type=all&a ...

  2. 20155306 白皎 0day漏洞——基础知识

    20155306 白皎 0day漏洞--(第一篇)基础知识 写在前面: 本次免考实践方向是0day漏洞,以博客的形式记录了我的学习实践过程.第一篇博客主要围绕什么是0day漏洞以及一些以后学习中需要的 ...

  3. 20155311《网络对抗》Web基础

    20155311<网络对抗>Web基础 实验过程 Web前端:HTML 使用netstat -aptn查看80端口是否被占用(上次实验设置为Apache使用80端口),如果被占用了就kil ...

  4. 理解 NgModelController 中相关方法和属性

    1. 理解$formatters和$parsers方法 angular的双向绑定可以实现view和model中的值自动同步,但有时候我们不想让用户输入的(view值)和发送给后台的(model值)并不 ...

  5. Redis基本数据类型介绍笔记

    Redis 数据类型 Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). String(字符串) st ...

  6. [C#]使用Join与GroupJoin将两个集合进行关联与分组

    本文为原创文章.源代码为原创代码,如转载/复制,请在网页/代码处明显位置标明原文名称.作者及网址,谢谢! 本文使用的开发环境是VS2017及dotNet4.0,写此随笔的目的是给自己及新开发人员作为参 ...

  7. H5——video百花齐放(浏览器自带的播放器)

    前言 手机自带浏览器的H5播放器 真是百花齐放啊(各个手机厂家有各个厂家的控件UI) 需求 手机浏览器木有控件条 自动播放 全屏处理 监控进度条 快进后退 自动播放 自动播放就给跪了 ios 安卓 为 ...

  8. LeetCode Search for a Range (二分查找)

    题意 Given a sorted array of integers, find the starting and ending position of a given target value. ...

  9. Apache Ignite 学习笔记(二): Ignite Java Thin Client

    前一篇文章,我们介绍了如何安装部署Ignite集群,并且尝试了用REST和SQL客户端连接集群进行了缓存和数据库的操作.现在我们就来写点代码,用Ignite的Java thin client来连接集群 ...

  10. D. Vasya and Arrays

    链接 [http://codeforces.com/contest/1036/problem/D] 题意 给你两个数组长度分别为n,m; 有这么一种操作,用某个数组的某个子区间元素之和代替这个子区间, ...