boost-date-time

Boost - Formatting sub second precision time with a time stamp

放肆的年华 提交于 2019-12-07 23:58:31
I need to get a nicely formatted timestamp (slightly modified ISO 8601) with millisecond precision. And example date would look like this: 2011-09-28 13:11:15.237-08:00 The formatting should be able to be overwridden as well. I've been playing around with boost::posix_time::microsec_clock::local_time() and boost::posix_time::time_facet which works just fine except when it comes to timestamps. Since posix time doesn't contain time zone information this is just not possible (I'm guessing) So, is there anything else I could use that has millisecond precision that contains timezone information or

unordered_map with gregorian dates

穿精又带淫゛_ 提交于 2019-12-07 05:19:50
问题 I would like to store boost::gregorian::date as key of a boost::unordered_map but I cannot compile the code as it is missing a proper hash function for this class. An easy solution would be converting to std::string and store it. I possibly would like to avoid this solution as using string is quite expensive. I tried to find some function exporting a date to number but I can read only the day() function and I am not sure if this is really suitable. Maybe I can calculate the number of days

using from_string with boost date

梦想的初衷 提交于 2019-12-07 01:43:47
问题 I have the following code: #include <iostream> #include <string> #include <iomanip> #include <locale> #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/gregorian/parsers.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time_io.hpp> using namespace boost::posix_time; using namespace boost::gregorian; int main(int argc, char *argv[]) { std::string ds("2011-01-02"); date dt(from_string(ds)); date_facet *f=new date

Ownership/delete'ing the facet in a locale (std::locale)

为君一笑 提交于 2019-12-06 17:18:28
问题 I wrote the following function to get a date/time string using boost.date_time. namespace bpt = boost::posix_time; string get_date_time_string(bpt::ptime time) { bpt::time_facet * facet(new bpt::time_facet); facet->format("%Y%m%d%H%M%S"); stringstream return_value; return_value.imbue(std::locale(std::locale::classic(), facet)); return_value << time; return return_value.str(); } I had a quick question about the ownership/ delete 'ing of the facet object. std::locale's constructor is not

How to get a local date-time from a time_t with boost::date_time?

偶尔善良 提交于 2019-12-06 13:47:50
问题 I'm using boost::date_time and I got a time_t, that have been generated by a library using the time() function from the C standard library. I'm looking for a way get a local time from that time_t. I'm reading the documentation and can't find any way to do this without providing a time zone, that I don't know about because it's dependant on the machine's locale, and I can't find any way to get one from it. What am I missing? 回答1: For this task, I'd ignore boost::date_time and just use

using from_string with boost date

我的梦境 提交于 2019-12-05 05:54:47
I have the following code: #include <iostream> #include <string> #include <iomanip> #include <locale> #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/gregorian/parsers.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time_io.hpp> using namespace boost::posix_time; using namespace boost::gregorian; int main(int argc, char *argv[]) { std::string ds("2011-01-02"); date dt(from_string(ds)); date_facet *f=new date_facet("%Y-%m-%d"); std::locale loc=std::locale(std::locale::classic(),f); std::cout.imbue(loc); std::cout<

How to get a local date-time from a time_t with boost::date_time?

亡梦爱人 提交于 2019-12-04 20:14:09
I'm using boost::date_time and I got a time_t, that have been generated by a library using the time() function from the C standard library. I'm looking for a way get a local time from that time_t. I'm reading the documentation and can't find any way to do this without providing a time zone, that I don't know about because it's dependant on the machine's locale, and I can't find any way to get one from it. What am I missing? For this task, I'd ignore boost::date_time and just use localtime (or localtime_r , if available) from the standard library. boost::posix_time::from_time_t() #include

C++: Will you choose boost::date_time or icu::date/time library?

[亡魂溺海] 提交于 2019-12-04 17:58:05
问题 My application requires custom time and date setting capabilities. I checked both ICU and boost::date_time libraries. Both appears to meet my requirements from a completeness point of view. I would like to know if there is any preference between the two and on what basis? which one will score on performance? 回答1: Without more information about your specific use case and environment, there's no way to give a definitive answer as to whether either library out-performs the other. As Xeo

C++: Will you choose boost::date_time or icu::date/time library?

依然范特西╮ 提交于 2019-12-03 12:39:56
My application requires custom time and date setting capabilities. I checked both ICU and boost::date_time libraries. Both appears to meet my requirements from a completeness point of view. I would like to know if there is any preference between the two and on what basis? which one will score on performance? Without more information about your specific use case and environment, there's no way to give a definitive answer as to whether either library out-performs the other. As Xeo suggested, profiling is the best way to address performance concerns. If your use case includes "general" date/time

Converting millisecond UTC to Human Readable Date_Time

淺唱寂寞╮ 提交于 2019-12-02 04:14:04
问题 I'm struggling to figure out how to preform a conversion with boost::date_time. I want to convert a millisecond value measured from the Unix epoch (00:00, Jan 1, 1970) to a human readable string - something like: 2/13/2012 15:20:11 would be ideal. I've tried some std C++ / boost suggestions I've seen but not had any luck just yet. Here is the code I use: long long ticksFromEpoch = 1329117220501; std::time_t tt = static_cast<time_t>(ticksFromEpoch); boost::posix_time::ptime dt = boost::posix