C++封装的时间和日期类,方便的操作时间。包括时间段、日期类、时间类。支持 时间/日期 加/减/比较,时间戳/字符串 相互转换。
一个包含三个类:Duration、Date、Time。
Duration 表示一个时间段
Date 表示一个日期,精确到秒,比如2016-01-01 12:00:00
Time 表示一个时间,精确到微秒,可以Date相互转换。
项目地址:
https://github.com/havesnag/date
文档地址:
http://www.baiyy.com/public/project/ecdate/index.html
使用教程:
http://www.baiyy.com/article/index/id/18/cid/2
基本示例
#include <iostream>
#include "date.h"
int main(int argc, char *argv[])
{
// The current time
ec::Time now;
// 10 hours
ec::Duration d(10, ec::Duration::Hour);
// After 10 hours
now += d;
// output like 2016-01-01 12:00:00
std::cout << now.toString() << std::endl;
return 0;
}