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 ...
随机推荐
- SQLite中的SELECT子句使用表达式
SQLite中的SELECT子句使用表达式 在SELECT语句中可以只有SELECT子句不写FROM子句.这些表达式列表将被单次计算,生成一行,然后组成工作表.这对于测试和判断独立表达式很有用.例如, ...
- 模拟页面获取的php数据(一)
<?php return array( "aData" => array(//通勤方式 "trafficType" => array( 0 = ...
- python-线程的暂停, 恢复, 退出
我们都知道python中可以是threading模块实现多线程, 但是模块并没有提供暂停, 恢复和停止线程的方法, 一旦线程对象调用start方法后, 只能等到对应的方法函数运行完毕. 也就是说一旦s ...
- pwcrack--一款集合多种md5解密的工具
项目开源地址:https://github.com/L-codes/pwcrack-framework Ruby2.5+ (tested with Ruby2.5.3 & Ruby 2.6.3 ...
- [USACO08DEC]Secret Message
OJ题号: 洛谷2922 思路: 字典树,每个结点记录经过该节点的字符串数cnt和以该结点结尾的字符串数量val. 每次询问时累加经过节点的val值和结尾结点的cnt值. #include<cs ...
- Eclipse中修改包名,提交SVN时报 is out of date,怎么办?
问题:Eclipse中修改包名,提交SVN时报 is out of date,怎么办?描述: Hi,大家好! 我的问题如题,在不考虑用TortoiseSVN客户端直接删除目录这个方法的情况下,有什么方 ...
- Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学
D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...
- 使用 IntraWeb (30) - TIWAppInfo、TIWMimeTypes、TIWAppCache
TIWAppInfo //IntraWeb 12.2.15 开始使用 TIWAppInfo 来获取应用的相关信息, 和 IWServerController.WebApplication 的某些属性有 ...
- spring cloud:config-server中@RefreshScope的"陷阱"
spring cloud的config-serfver主要用于提供分布式的配置管理,其中有一个重要的注解:@RefreshScope,如果代码中需要动态刷新配置,在需要的类上加上该注解就行.但某些复杂 ...
- git代码合并:Merge、Rebase的选择
代码合并:Merge.Rebase的选择 Zhongyi Tong edited this page on Dec 7, 2015 · 3 revisions Pages 19 Home 2.1 快速 ...