boost-date-time

Boost ptime: how to format data in a way browsers send inside headers of http requests?

不想你离开。 提交于 2020-01-06 12:46:15
问题 I need to format my ptime in such way Wed, 21 Jan 2004 19:51:30 GMT How to do such thing with boost? (so it would look like data format of HTTP servers Expires and Last-Modified and Date response headers ) 回答1: #include <locale> #include <string> #include <iostream> #include <sstream> #include <boost/date_time/posix_time/posix_time.hpp> std::string current_time_formatted() { namespace bpt = boost::posix_time; static char const* const fmt = "%a, %d %b %Y %H:%M:%S GMT"; std::ostringstream ss; /

Boost ptime: how to format data in a way browsers send inside headers of http requests?

。_饼干妹妹 提交于 2020-01-06 12:45:08
问题 I need to format my ptime in such way Wed, 21 Jan 2004 19:51:30 GMT How to do such thing with boost? (so it would look like data format of HTTP servers Expires and Last-Modified and Date response headers ) 回答1: #include <locale> #include <string> #include <iostream> #include <sstream> #include <boost/date_time/posix_time/posix_time.hpp> std::string current_time_formatted() { namespace bpt = boost::posix_time; static char const* const fmt = "%a, %d %b %Y %H:%M:%S GMT"; std::ostringstream ss; /

How do I get the current “localized pattern” for the date and time of an std::locale

不羁的心 提交于 2019-12-23 10:28:25
问题 So far, I'm able to get the current locale, but I want to get the date format for that particular locale. Can this be done with the standard library. #include <locale> int _tmain(int argc, _TCHAR* argv[]) { // Print the current locale std::cout << std::locale("").name().c_str() << "\n"; // TODO: get the locale's date pattern, example for US it's (mm/dd/yyyy) std::cout << "date pattern: \n"; } 回答1: If you just want to cast a date to the corresponding string you can use std::time_put<char> :

How to convert a fractional epoch timestamp (double) to an std::chrono::time_point?

穿精又带淫゛_ 提交于 2019-12-23 07:46:36
问题 I have a fractional epoch timestamp, represented as double , that I would like to convert to an appropriate std::chrono::time_point . The epoch is the usual UNIX epoch since 1/1/1970. I know that there exists std::chrono::system_clock::from_time_t , but a time_t does not have a fractional part. What would be the best way to do this with C++11 means? This question is related to unix timestamp to boost::posix_time::ptime, except that it's asking for the C++11 rather than Boost version of it.

How do I get the current UTC offset (time zone)?

可紊 提交于 2019-12-21 16:38:30
问题 How do I get the current UTC offset (as in time zone, but just the UTC offset of the current moment)? I need an answer like "+02:00". 回答1: There are two parts to this question: Get the UTC offset as a boost::posix_time::time_duration Format the time_duration as specified Apparently, getting the local time zone is not exposed very well in a widely implemented API. We can, however, get it by taking the difference of a moment relative to UTC and the same moment relative to the current time zone,

How do I get the current UTC offset (time zone)?

不问归期 提交于 2019-12-21 16:38:11
问题 How do I get the current UTC offset (as in time zone, but just the UTC offset of the current moment)? I need an answer like "+02:00". 回答1: There are two parts to this question: Get the UTC offset as a boost::posix_time::time_duration Format the time_duration as specified Apparently, getting the local time zone is not exposed very well in a widely implemented API. We can, however, get it by taking the difference of a moment relative to UTC and the same moment relative to the current time zone,

How to get the current time zone?

淺唱寂寞╮ 提交于 2019-12-17 16:31:57
问题 In most of the examples I had seen: time_zone_ptr zone( new posix_time_zone("MST-07") ); But I just want to get the current time zone for the machine that runs the code. I do not want to hard code the time zone name. 回答1: Plain posix: call tzset, use tzname. #include <ctime> tzset(); time_zone_ptr zone(new posix_time_zone(tzname[localtime(0)->tm_isdst])); Posix with glibc/bsd additions: time_zone_ptr zone(new posix_time_zone(localtime(0)->tm_zone)); The above are abbreviated Posix timezones,

How to link to boost date_time

此生再无相见时 提交于 2019-12-11 09:07:19
问题 Example I have an Rcpp function where I would like to call boost::posix_time::time_from_string() . I've taken the example code from the boost documentation and translated it to a c++ function using Rcpp library(Rcpp) cppFunction( includes = ' #include <boost/date_time/posix_time/posix_time.hpp> ', code = ' void time_test() { std::string t = "2002-01-20 23:59:59.000"; boost::posix_time::ptime pt(boost::posix_time::time_from_string(t)); Rcpp::Rcout << "time from string: " << pt << std::endl; }

Parse time_period expression with Boost::Spirit

人盡茶涼 提交于 2019-12-10 17:48:43
问题 I need to parse following EBNF expression with Boost::Spirit. period ::= date_part [time_part] , date_part [time_part] time_part ::= hours:minutes[:seconds] date_part ::= day.month.year For example, 10.06.2014 10:00:15, 11.07.2014 . I made my grammar in two ways, but can't exactly get working example. 1) First attempt struct Parser: grammar<std::string::const_iterator, space_type> { Parser(): Parser::base_type(datetime_) { using boost::spirit::int_; using boost::spirit::qi::_1; using boost:

Boost - Formatting sub second precision time with a time stamp

佐手、 提交于 2019-12-08 07:10:45
问题 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,