利用boost获取时间并格式化
来源:互联网 发布:简易平面图软件 编辑:程序博客网 时间:2024/06/03 12:57
利用boost来获取当前时间又方便快捷,还不用考虑跨平台的问题。
1. 输出YYYYMMDD
- #include <boost/date_time/gregorian/gregorian.hpp>
- #define BOOST_DATE_TIME_SOURCE
- std::string strTime = boost::gregorian::to_iso_string(\
- boost::gregorian::day_clock::local_day());
- std::cout << strTime.c_str() << std::endl;
2. 输出YYYYMMDD-HH:MM:SS
- #include <boost/date_time/posix_time/posix_time.hpp>
- #define BOOST_DATE_TIME_SOURCE
- std::string strTime = boost::posix_time::to_iso_string(\
- boost::posix_time::second_clock::local_time());
- // 这时候strTime里存放时间的格式是YYYYMMDDTHHMMSS,日期和时间用大写字母T隔开了
- int pos = strTime.find('T');
- strTime.replace(pos,1,std::string("-"));
- strTime.replace(pos + 3,0,std::string(":"));
- strTime.replace(pos + 6,0,std::string(":"));
- std::cout << strTime.c_str() << std::endl;
- #include <boost/date_time/posix_time/posix_time.hpp>
- #include <boost/thread.hpp>
- #define BOOST_DATE_TIME_SOURCE
- boost::posix_time::ptime time_now,time_now1;
- boost::posix_time::millisec_posix_time_system_config::time_duration_type time_elapse;
- // 这里为微秒为单位;这里可以将microsec_clock替换成second_clock以秒为单位;
- time_now = boost::posix_time::microsec_clock::universal_time();
- // sleep 100毫秒;
- boost::this_thread::sleep(boost::posix_time::millisec(100));
- time_now1 = boost::posix_time::microsec_clock::universal_time();
- time_elapse = time_now1 - time_now;
- // 类似GetTickCount,只是这边得到的是2个时间的ticket值的差,以微秒为单位;
- int ticks = time_elapse.ticks();
- // 得到两个时间间隔的秒数;
- int sec = time_elapse.total_seconds();
转自:http://blog.csdn.net/morebread/article/details/6742957
- 利用boost获取时间并格式化
- 利用boost获取时间并格式化
- 利用boost获取时间并格式化
- 利用boost获取时间并格式化
- 利用boost获取时间并格式化
- 利用boost获取时间并格式化
- 利用boost计算运行时间间隔及获取系统时间并格式化
- 获取系统时间,并格式化
- 获取当前时间并格式化
- js获取时间并格式化
- 利用boost库获取GMT时间
- Java获取系统时间并格式化输出
- jsp页面获取当前时间并格式化
- c 获取当前时间并格式化输出
- js如何获取当前时间 并格式化
- JS 获取当前时间并格式化
- Java 获取时间毫秒数并格式化
- js获取当前时间并格式化
- debian 关闭图形界面
- 关于RAC中监听配置IP=FIRST的说明
- jsp中的file类
- USASO Greedy Gift Givers
- GDI+中发生一般性错误
- 利用boost获取时间并格式化
- JAVA 国外 相关技术 站点
- HTML & XML 转义字符
- 编译PhysBAM
- PDF文件预览控件
- VB该部件为注册的解决办法
- SicilyOJ(SOJ) 1302 Magic Square(Merzirac解奇幻方)
- Keil IAR - Cortex M3 Debugging in On-chip SRAM
- goAhead官方源码包和文件上传补丁