commit 9732bf7c748beaddfdb7e2485c79675afaf6a51d Author: panyufeng <3043130461@qq.com> Date: Mon Jul 12 21:32:36 2021 +0800 提交日期demo diff --git a/boost_test/Makefile b/boost_test/Makefile new file mode 100644 index 0000000..b75ca17 --- /dev/null +++ b/boost_test/Makefile @@ -0,0 +1,2 @@ +boost_test:boost_test.cpp + g++ $^ -o $@ \ No newline at end of file diff --git a/boost_test/boost_test.cpp b/boost_test/boost_test.cpp new file mode 100644 index 0000000..7a88fc0 --- /dev/null +++ b/boost_test/boost_test.cpp @@ -0,0 +1,24 @@ +#include +#include + +using namespace std; + +int main() +{ + using boost::lexical_cast; + int a = lexical_cast("123"); + double b = lexical_cast("123.0123456789"); + string s0 = lexical_cast(a); + string s1 = lexical_cast(b); + cout << "number: " << a << " " << b << endl; + cout << "string: " << s0 << " " << s1 << endl; + int c = 0; + try { + c = lexical_cast("abcd"); + } + catch (boost::bad_lexical_cast& e) { + cout << e.what() << endl; + } + + return 0; +} \ No newline at end of file diff --git a/boost_test/boost_test.sln b/boost_test/boost_test.sln new file mode 100644 index 0000000..fcc702d --- /dev/null +++ b/boost_test/boost_test.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1525 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "boost_test", "boost_test.vcxproj", "{BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x64.ActiveCfg = Debug|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x64.Build.0 = Debug|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x86.ActiveCfg = Debug|Win32 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x86.Build.0 = Debug|Win32 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x64.ActiveCfg = Release|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x64.Build.0 = Release|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x86.ActiveCfg = Release|Win32 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5F7FB1D9-E114-4EC1-B5F5-4C115CC3FE7C} + EndGlobalSection +EndGlobal diff --git a/boost_test/boost_test.vcxproj b/boost_test/boost_test.vcxproj new file mode 100644 index 0000000..1274750 --- /dev/null +++ b/boost_test/boost_test.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED} + Win32Proj + boosttest + 10.0.17763.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + D:\c++\lib\boost\include\boost-1_76;$(ReferencePath) + D:\c++\lib\boost\lib;$(LibraryPath) + D:\c++\lib\boost\include\boost-1_76;$(IncludePath) + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\c++\lib\boost\include\boost-1_76;%(AdditionalIncludeDirectories) + + + Console + true + D:\c++\lib\boost\lib\;%(AdditionalLibraryDirectories) + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/boost_test/boost_test.vcxproj.filters b/boost_test/boost_test.vcxproj.filters new file mode 100644 index 0000000..0baf3ec --- /dev/null +++ b/boost_test/boost_test.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/boost_timer/Makefile b/boost_timer/Makefile new file mode 100644 index 0000000..5194d6e --- /dev/null +++ b/boost_timer/Makefile @@ -0,0 +1,2 @@ +boost_timer:boost_timer.cpp + g++ $^ -o $@ \ No newline at end of file diff --git a/boost_timer/boost_timer.cpp b/boost_timer/boost_timer.cpp new file mode 100644 index 0000000..af80aec --- /dev/null +++ b/boost_timer/boost_timer.cpp @@ -0,0 +1,174 @@ + +//#define DATE_TIME_NO_DEFAULT_CONSTRUCTOR //不希望出现无效时间 + +#include +#include +#include + +#include +#include + +using namespace std; +using namespace boost; + + +using namespace boost::gregorian; +using namespace boost::posix_time; + + +//自定义字面值 c11 新增了重载operator""的特性 +days operator"" _D(unsigned long long n) +{ + return days(n); +} + + +weeks operator"" _W(unsigned long long n) { + return weeks(n); +} + + +date operator"" _YMD(const char* s, std::size_t) { + return from_string(s); +} + +int main() +{ + timer t; //计时器 + cout << "max timespan:" << t.elapsed_max() / 3600 << "h" << endl; // 可度量的最大时间 + cout << "min timespan:" << t.elapsed_min() << "s" << endl; //最小时间 + cout << "now time elapsed:" << t.elapsed() << "s" << endl; //流逝的时间 + + progress_timer t2; //析构时会打印流逝时间elapsed() +// progress_timer t3 = t2; //继承自noncopyable 不行 +// progress_timer t3(t2); //继承自noncopyable 不行 + + + + +/******************************DATE*******************************/ + gregorian::date d(2021,7,11); + d = day_clock::local_day(); //当前时间 + gregorian::date d2 = from_string("2021-7-11"); + //d = from_undelimited_string("20210711"); + cout << to_iso_extended_string(d) << endl; // 日期以指定格式打印 + cout << to_iso_string(d) << endl; + cout << to_simple_string(d) << endl; + + if (d > d2) { //支持比较操作符 + cout << "1111" << endl; + } + + + int inweek = d.day_of_week(); + cout << inweek << endl; //星期几 + int numInYear = d.day_of_year(); + cout << numInYear << endl; //一年中的第几天 + +// 与C结构 tm 相互转换 + tm _tm = to_tm(d); + date_from_tm(_tm); + +/******************************DATE END*******************************/ + +//日期计算 + days day(1); //1天 + weeks week(1); //1个星期 + months mon(1); //1个月 + years year(1); //1年 + + d += day ; + d += week; + d += mon; + d += year; + cout << to_iso_extended_string(d) << endl; + + // + date ddd(2021, 3, 30); + ddd -= months(1); //20210228 //注意 这里得到的是月末 + + + //日期区间 左闭右开区间 + date_period dp(d, days(20)); + + if (dp.contains(d + days(2))) //是否包含 is_before is_after 在前在后、 + cout << 111 << endl; + + //还有交集、并集等 不常用就不一一讲了 + + //日期迭代器 好像没啥用。。。 + //day_iterator iter(d); + + +/******************************TIME*******************************/ + + posix_time::time_duration time(1,10,30,1000);//时、分、秒、微秒 + cout << time << endl; + hours houre(1); + minutes min(10); + seconds sec(59); + millisec ms(1000); + time_duration time2 = houre + min + sec + ms; + cout << to_simple_string(time2) << endl; //以指定格式打印 + + //与 date类似也可以用于比较 + + //转换到tm + _tm = to_tm(time2); //但是不能反向转换 + + //默认精确度到微秒,纳秒相关的类函数默认都不可用!! 纳秒用得也不多,就不讨论了。。 + +/******************************TIME END*******************************/ + + +/******************************DATE_TIME*******************************/ + ptime _ptime(d, time); //同时包含 日期和时间的结构 + + ptime p1 = time_from_string("2021-7-12 01:00:00"); + + ptime p2 = from_iso_string("20210712T020000"); + + ptime p3 = second_clock::local_time(); //精确到秒 + + ptime p4 = second_clock::universal_time(); //精确到微秒 + + //操作ptime 可以分解为 date time 来处理 + //也支持加减处理 + p3 += hours(3); + cout << to_simple_string(p3) << endl; + cout << to_iso_string(p3) << endl; + cout << to_iso_extended_string(p3) << endl; //源码是以T为分隔,可以自己改为空格 + + //转为c结构: + _tm = to_tm(p3); + + ptime_from_tm(_tm); + + ptime p5 = from_time_t(std::time(0)); + + std::time_t time_t = to_time_t(p5); + + //时间区间 time_period //类似于 date_period 不在细说了 + +/******************************DATE_TIME_END*******************************/ + + days d11 = 11_D; //这个用来装逼还挺有一套,基础撇点的都不知道,哈哈 + weeks w3 = 3_W; + date d20110712 = "2021-7-12"_YMD; + + + //格式化时间 + + //这个玩意儿 继承自std::locale::facet 是个智能指针,当引用计数为0 就会自动delete掉 。 所以当创在栈上,或创在堆上手动delete都会飞掉!注意了! + date_facet *facet = new date_facet("%Y年%m月%d日"); + cout.imbue(locale(cout.getloc(),facet)); + cout << d20110712 << endl; + + time_facet* tfacet = new time_facet("%Y年%m月%d日 %H点%M分%S%F秒"); + cout.imbue(locale(cout.getloc(), tfacet)); + cout << p4 << endl; + + + return 0; +} + diff --git a/boost_timer/boost_timer.sln b/boost_timer/boost_timer.sln new file mode 100644 index 0000000..03c0b7e --- /dev/null +++ b/boost_timer/boost_timer.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1525 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "boost_timer", "boost_timer.vcxproj", "{BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x64.ActiveCfg = Debug|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x64.Build.0 = Debug|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x86.ActiveCfg = Debug|Win32 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Debug|x86.Build.0 = Debug|Win32 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x64.ActiveCfg = Release|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x64.Build.0 = Release|x64 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x86.ActiveCfg = Release|Win32 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5F7FB1D9-E114-4EC1-B5F5-4C115CC3FE7C} + EndGlobalSection +EndGlobal diff --git a/boost_timer/boost_timer.vcxproj b/boost_timer/boost_timer.vcxproj new file mode 100644 index 0000000..5b59744 --- /dev/null +++ b/boost_timer/boost_timer.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {BE9452A1-E1E4-4E46-8CB5-3005DEE778ED} + Win32Proj + boosttest + 10.0.17763.0 + boost_timer + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + D:\c++\lib\boost\include\boost-1_76;$(ReferencePath) + D:\c++\lib\boost\lib;$(LibraryPath) + D:\c++\lib\boost\include\boost-1_76;$(IncludePath) + + + false + + + false + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\c++\lib\boost\include\boost-1_76;%(AdditionalIncludeDirectories) + + + Console + true + D:\c++\lib\boost\lib\;%(AdditionalLibraryDirectories) + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/boost_timer/boost_timer.vcxproj.filters b/boost_timer/boost_timer.vcxproj.filters new file mode 100644 index 0000000..84c3526 --- /dev/null +++ b/boost_timer/boost_timer.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file