Questions tagged [boost-date-time]

Boost.Date_Time is a set of C++ date-time libraries based on generic programming concepts.

Boost.Date_Time is a set of C++ date-time libraries based on generic programming concepts.

Date-time libraries provide fundamental infrastructure for most development projects. However, most of them have limitations in their ability to calculate, format, convert, or perform some other functionality. For example, most libraries do not correctly handle leap seconds, provide concepts such as infinity, or provide the ability to use high resolution or network time sources. These libraries also tend to be rigid in their representation of dates and times. Thus customized policies for a project or subproject are not possible.

Programming with dates and times should be almost as simple and natural as programming with strings and integers. Applications with lots of temporal logic can be radically simplified by having a robust set of operators and calculation capabilities. Classes should provide the ability to compare dates and times, add lengths or time durations, retrieve dates and times from clocks, and work naturally with date and time intervals.

Another motivation for development of the library was to apply modern C++ library design techniques to the date-time domain. Really to build a framework for the construction of building temporal types. For example, by providing iterators and traits classes to control fundamental properties of the library. To the authors knowledge this library is the only substantial attempt to apply modern C++ to a date-time library.

127 questions
4
votes
1 answer

Using boost::date, how do I compute "last Monday"?

This is how one gets "two days ago" using boost::date: boost::gregorian::date today = boost::gregorian::day_clock::local_day(); boost::date_time::day_functor day_offset(-2); boost::gregorian::date modified = today +…
screwnut
  • 1,367
  • 7
  • 26
4
votes
2 answers

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

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…
Stéphane
  • 19,459
  • 24
  • 95
  • 136
3
votes
2 answers

How do you format with Boost.Date_Time without leading zeros?

How can you format a boost::posix_time::ptime object without padding the numbers with zeros? For example, I want to display 6/7/2011 6:30:25 PM and not 06/07/2011 06:30:25 PM. In .NET, the format string would be something like "m/d/yyyy h:mm:ss…
Eric
  • 2,098
  • 4
  • 30
  • 44
3
votes
1 answer

boost::posix_time fails in release build

I want to open a new log file each a program runs, so I create a filename with the current time. FILE * fplog; void OpenLog() { boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); char buf[256]; …
ravenspoint
  • 19,093
  • 6
  • 57
  • 103
3
votes
3 answers

Get time_t / timeval corresponding to ( local_timezone ) midnight on a given date

Given a time_t or struct timeval, how do I get the timeval or time_t of midnight EST/EDT ( local timezone ) on that day ? As in assuming local timezone is EST/EDT, given a time_t corresponding to say 2010-11-30 08:00:00 EST/EDT, the expected answer…
Humble Debugger
  • 4,439
  • 11
  • 39
  • 56
3
votes
2 answers

Epoch time to date/time format in boost c++

In Linux, i am reading epoch time from "/proc/stat" as btime and i want to convert to readable date and time format with c++ boost. I have tried below things and date is working properly. time_t btime_ = 1505790902; //This is epoch time read…
Neel
  • 451
  • 1
  • 9
  • 23
3
votes
1 answer

Using boost parse datetime string: With single digit hour format

I am working on code which needs to compile on NDK toolchain. Unfortunately, latest version only supports till gcc4.9 which does not support C++11 datetime parsing. I have a date time string which I need to send thru two-three formats to figure out…
abhilekh
  • 101
  • 1
  • 5
3
votes
1 answer

c++ boost::posix_time::ptime default value

I have a member variable in my class: class Foo { // ... private: boost::posix_time::ptime t; } I want to initialize it in the constructor to a well known value such that I know it hasn't been set by the program yet: Foo::Foo() : t(NULL) //…
3
votes
1 answer

boost::gregorian input_facet unexpected results

I have a question regarding reading boost::gregorian::date object from a formatted string. When the input string has the format specified, it works as expected. E.g., the code below std::string fmt = "%Y-%m-%d"; std::string date_str =…
pausag
  • 136
  • 8
3
votes
1 answer

boost::local_time Does not read correct iso_extended_format

I need to read time with ISO extended format, and convert it to UTC time, like Javascript's Date objects do: new Date("2014-12-19T15:53:14.533+01:00") 2014-12-19T14:53:14.533Z In boost, there is no boost::posix_time::from_iso_extended_string and …
Arpegius
  • 5,817
  • 38
  • 53
3
votes
1 answer

Parse time_period expression with Boost::Spirit

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…
adil
  • 45
  • 5
3
votes
0 answers

How to format boost::date_time duration for output with millisecond precision?

I'm looking for a concise solution to output a boost::posix_time::time_duration with a precision of milliseconds: There should be exactly 3 fractional-second digits. The default format produces 6 fractional digits (or none, if they are all…
3
votes
2 answers

Why is there no boost::date_time with microsec resolution on Windows?

On Win32 system boost::date_time::microsec_clock() is implemented using ftime, which provides only millisecond resolution: Link to doc There are some questions/answers on Stackoverflow stating this and linking the documentation, but not explaining…
MOnsDaR
  • 8,401
  • 8
  • 49
  • 70
2
votes
1 answer

Converting millisecond UTC to Human Readable Date_Time

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…
Pat Mustard
  • 1,852
  • 9
  • 31
  • 58
2
votes
1 answer

C++: Should I be using Boost.Date_Time Posix Time or Local Time?

I'm making changes to an existing multiplatform library. The library currently uses time_t and time(NULL) to store "timestamps" of important events, but the seconds-resolution is no longer enough. The library already uses Boost for different…
Stéphane
  • 19,459
  • 24
  • 95
  • 136
1 2
3
8 9