boost-date-time

Converting millisecond UTC to Human Readable Date_Time

こ雲淡風輕ζ 提交于 2019-12-01 22:57:58
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_time::from_time_t(tt); // Create a time_zone_ptr for the desired time zone and use it to create a local

Creating a boost::posix_time::ptime object from a 64 bit integer second count

爱⌒轻易说出口 提交于 2019-12-01 19:14:56
I have a 32 bit Linux system in which I have to record data that is timestamped with a UINT32 second offset from an epoch of 1901-01-01 00:00:00. Calculating the timestamp is ok for me as I can use the 64 bit ticks() counter and ticks_per_second() functions to generate the seconds since epoch as follows (I only require second level resolution) const ptime ptime_origin(time_from_string("1901-01-01 00:00:00")); time_duration my_utc = microsec_clock::universal_time() - ptime_origin; boost::int64_t tick_per_sec = my_utc.ticks_per_second(); boost::int64_t tick_count = my_utc.ticks(); boost::int64_t

Creating a boost::posix_time::ptime object from a 64 bit integer second count

烈酒焚心 提交于 2019-12-01 18:23:31
问题 I have a 32 bit Linux system in which I have to record data that is timestamped with a UINT32 second offset from an epoch of 1901-01-01 00:00:00. Calculating the timestamp is ok for me as I can use the 64 bit ticks() counter and ticks_per_second() functions to generate the seconds since epoch as follows (I only require second level resolution) const ptime ptime_origin(time_from_string("1901-01-01 00:00:00")); time_duration my_utc = microsec_clock::universal_time() - ptime_origin; boost::int64

unix timestamp to boost::posix_time::ptime

隐身守侯 提交于 2019-12-01 16:27:35
I need to convert double with number of seconds since the epoch to ptime . I'm prety sure there must be an easy way to do this, but I couldn't find anything. Thanks. Edit: The original timestamp is floating point. I can't change it and i don't want to lose the sub-second precision. Use the from_time_t() conversion function. A time_t is a UNIX timestamp, i.e. the number of seconds since the epoch. For a machine that has boost date/time compiled to the default level of microsecond resolution, try this: double ts = 1250524800.5; // Use floor() here if seconds are always positive. time_t

unix timestamp to boost::posix_time::ptime

心不动则不痛 提交于 2019-12-01 15:12:32
问题 I need to convert double with number of seconds since the epoch to ptime . I'm prety sure there must be an easy way to do this, but I couldn't find anything. Thanks. Edit: The original timestamp is floating point. I can't change it and i don't want to lose the sub-second precision. 回答1: Use the from_time_t() conversion function. A time_t is a UNIX timestamp, i.e. the number of seconds since the epoch. 回答2: For a machine that has boost date/time compiled to the default level of microsecond

weekdays' duration using boost date

天大地大妈咪最大 提交于 2019-12-01 09:40:04
Is there a way to get only the no. of weekdays between 2 boost dates. In the following, I'm only getting calendar days. date begin_dt(2011,Aug,3); date end_dt(day_clock::local_day()); days duration=end_dt-begin_dt; std::cout<<"calendar days between begin & end date are: "<<duration<<std::endl; Perhaps the simplest way is to run a day_iterator from start to finish: #include <iostream> #include <boost/date_time.hpp> int main() { using namespace boost::gregorian; date begin_dt(2011,Aug,3); date end_dt(day_clock::local_day()); days duration=end_dt-begin_dt; std::cout<<"calendar days between begin

weekdays' duration using boost date

家住魔仙堡 提交于 2019-12-01 07:32:44
问题 Is there a way to get only the no. of weekdays between 2 boost dates. In the following, I'm only getting calendar days. date begin_dt(2011,Aug,3); date end_dt(day_clock::local_day()); days duration=end_dt-begin_dt; std::cout<<"calendar days between begin & end date are: "<<duration<<std::endl; 回答1: Perhaps the simplest way is to run a day_iterator from start to finish: #include <iostream> #include <boost/date_time.hpp> int main() { using namespace boost::gregorian; date begin_dt(2011,Aug,3);

What is the C++11 equivalent to boost::date_time::not_a_date_time?

℡╲_俬逩灬. 提交于 2019-11-30 18:33:37
问题 I'm modifying an old project, and at the same time I'm updating several things to bring it up to C++11. I'd like to replace various uses of boost::date_time with the new functionality in std::chrono. But I cannot figure out what is the C++11 equivalent of boost::date_time::not_a_date_time. Isn't there an equivalent in C++11 to indicate that a time_point variable hasn't yet been assigned, or doesn't contain a valid timestamp? 回答1: Given the fact that it exists as part of a group bool is

Simplest way to get current time in current timezone using boost::date_time?

孤者浪人 提交于 2019-11-30 17:58:05
If I do date +%H-%M-%S on the commandline (Debian/Lenny), I get a user-friendly (not UTC, not DST-less, the time a normal person has on their wristwatch) time printed. What's the simplest way to obtain the same thing with boost::date_time ? If I do this: std::ostringstream msg; boost::local_time::local_date_time t = boost::local_time::local_sec_clock::local_time( boost::local_time::time_zone_ptr() ); boost::local_time::local_time_facet* lf( new boost::local_time::local_time_facet("%H-%M-%S") ); msg.imbue(std::locale(msg.getloc(),lf)); msg << t; Then msg.str() is an hour earlier than the time I

Simplest way to get current time in current timezone using boost::date_time?

风格不统一 提交于 2019-11-30 02:51:47
问题 If I do date +%H-%M-%S on the commandline (Debian/Lenny), I get a user-friendly (not UTC, not DST-less, the time a normal person has on their wristwatch) time printed. What's the simplest way to obtain the same thing with boost::date_time ? If I do this: std::ostringstream msg; boost::local_time::local_date_time t = boost::local_time::local_sec_clock::local_time( boost::local_time::time_zone_ptr() ); boost::local_time::local_time_facet* lf( new boost::local_time::local_time_facet("%H-%M-%S")