c++11 输出时间
C++11中输出当前时间最直接的方法:
std::time_t t2 = std::time(nullptr);
cout << std::put_time(std::localtime(&t), "%Y-%m-%d %H.%M.%S") << "." << msecs << endl;
这种方法可以输出年月日时分秒,不过却不能输出毫秒,如果要输出毫秒需要用下面的方法:
auto n = chrono::system_clock::now();
auto m = n.time_since_epoch();
auto diff = duration_cast<milliseconds>(ms).count();
auto const msecs = diff % ; std::time_t t = system_clock::to_time_t(n1);
cout << std::put_time(std::localtime(&t), "%Y-%m-%d %H.%M.%S") << "." << msecs << endl;
将绝对时间转换为标准时间字符串的方法:
#include <string>
#include <chrono>
#include <cinttypes>
#include <ctime>
#include <sstream>
#include <iomanip> std::string millisecond_to_str(std::int64_t milliseconds)
{
std::chrono::milliseconds ms(milliseconds);
std::chrono::time_point<std::chrono::high_resolution_clock, std::chrono::milliseconds> t1(ms);
std::time_t t = std::chrono::system_clock::to_time_t(t1); std::stringstream ss;
auto const msecs = ms.count() % ;
ss << std::put_time(std::localtime(&t), "%Y-%m-%d %H.%M.%S") << "." << msecs;
return ss.str();
}
c++11 输出时间的更多相关文章
- Java abstract类的基本使用 和 [abstract类实现]打印1000以内的所有素数并输出时间
笔记: /** 关键字abstract ,实现抽象类,相当于给出类的大纲,子类只管继承,但抽象类不可被实例化! * 1.抽象方法只保留方法的功能,而具体的执行,交给继承抽象类的子类,由子类重写所有的抽 ...
- c++11 Chrono时间库
c++11 Chrono时间库 http://en.cppreference.com/mwiki/index.php?title=Special%3ASearch&search=chrono ...
- (转)linux 中使用ls指定输出时间格式
linux 中使用ls指定输出时间格式 原文:http://blog.csdn.net/chaofanwei/article/details/13018753 ls -l --time-style=x ...
- java中如何按一定的格式输出时间, 必须给出例子
题目2: 按一定的格式输出时间 import java.util.*;import java.text.SimpleDateFormat;public class Test { public s ...
- python的日志模块:logging;django的日志系统;django日志输出时间修改
Django的log,主要是复用Python标准库中的logging模块,在settings.py中进行配置 源代码 1.__init__.py包含以下类: StreamHandler Formatt ...
- struts2 <s:property/>标签的使用--输出时间格式转换
转载地址http://hi.baidu.com/nonyi_com/blog/item/acf1b8d74b6cf63e07088bc4.html 最近在使用struts2的<s:propert ...
- Asp.Net MVC5 格式化输出时间日期
刚好用到这个,网上找的全部是输出文本框内容的格式化日期时间 而我需要只是在一个表格中的单元个中输出单纯的文字 最后在MSDN上找到 HtmlHelper.FormatValue 方法 public s ...
- tp在页面输出时间
输出时间戳 :{:time()} 输出当前时间:{:date('Y-m-d H:i:s')} 输出1970的时间:{:date('Y-m-d H:i:s',$vo['create_time'])}
- python学习笔记 | strftime()格式化输出时间
time模块 import time t = time.strftime("%Y-%m-%d %H:%M:%S") print(t) datetime模块 import datet ...
随机推荐
- css实现幻灯片播放效果
用css实现幻灯片播放是最基础的,闲下来没事就试着写了一下,如果有不够完善或者方法不好的地方还请指点.下面我就用两种方法实现css花灯片效果. 方法1:定位.通过position属性改变left值 h ...
- 014.Docker Harbor+Keepalived+LVS+共享存储高可用架构
一 多Harbor高可用介绍 共享后端存储是一种比较标准的方案,将多个Harbor实例共享同一个后端存储,任何一个实例持久化到存储的镜像,都可被其他实例中读取.通过前置LB组件,如Keepalived ...
- vue+ElementUI使用笔记
1,使用表单验证: //定义验证规则 window.varifyUtil = { //验证数字 validateNumber: function(rule, value, callback){ if ...
- cocoa组件化开发
[转载:http://www.cocoachina.com/ios/20171120/21234.html](http://www.cocoachina.com/ios/20171120/21234. ...
- [环境]vscode中python虚拟环境
在项目.vscode/settings.json下设置 { "python.pythonPath": "/path/to/python2.7"}
- memcache 在php中的用法
memcached 的安装方法详见我博客的另一个页面:http://www.cnblogs.com/chrdai/p/6656443.html 用法: 一.memcache 连接命令: 1.memca ...
- 前端性能优化 —— 减少HTTP请求
简要:对于影响页面呈选 的因素有3个地方:服务器连接数据库并计算返回数据 , http请求以及数据(文件)经过网络传输 , 文件在浏览器中计算渲染呈选: 其中大约80%的时间都耗在了http请求上,所 ...
- Cocos Creator的小点
声明的时候,变量如此:但用的时候就变成了border,找了很久的问题,一直没找到啊,后来就发现命名的时候和内置的一定不要太相似否则后悔的只能是自己: cc.Class({ extends: cc.Co ...
- netbeans连接数据库SQLserver2008
数据库设置 第一步:配置SQL,打开SQL server 2008文件下的配置工具里的SQL server配置管理器 设置MSSQLSERVER协议中,开启TCP/IP,端口设置为1433 在SQL ...
- (总结)Ubuntu apt-get apt-cache命令 使用
http://rsljdkt.iteye.com/blog/1142463 apt-cache search wubipinyin apt-get命令本身并不具有管理软件包功能,只是提供了一个软件包管 ...