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
60
votes
4 answers

How to parse date/time from string?

Input: strings with date and optional time. Different representations would be nice but necessary. The strings are user-supplied and can be malformed. Examples: "2004-03-21 12:45:33" (I consider this the default layout) "2004/03/21 12:45:33"…
Gabriel Schreiber
  • 2,166
  • 1
  • 20
  • 33
52
votes
6 answers

Performance of dynamic_cast?

Before reading the question: This question is not about how useful it is to use dynamic_cast. Its just about its performance. I've recently developed a design where dynamic_cast is used a lot. When discussing it with co-workers almost everyone says…
MOnsDaR
  • 8,401
  • 8
  • 49
  • 70
44
votes
5 answers

How do I convert boost::posix_time::ptime to time_t?

Is there some "standard" way or the best I can do is to compute it directly by subtracting from gregorian::date(1970,1,1)?
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
29
votes
5 answers

How to get the current time zone?

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.
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
21
votes
2 answers

Getting the current time as a YYYY-MM-DD-HH-MM-SS string

I'm trying to get the current time as a "YYYY-MM-DD-HH-MM-SS" formatted string in an elegant way. I can take the current time in ISO format from Boost's "Date Time" library, but it has other delimiting strings which won't work for me (I'm using this…
ltjax
  • 15,837
  • 3
  • 39
  • 62
16
votes
1 answer

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

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"); …
decimus phostle
  • 1,040
  • 2
  • 13
  • 28
13
votes
3 answers

unix timestamp to boost::posix_time::ptime

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…
cube
  • 3,867
  • 7
  • 32
  • 52
12
votes
3 answers

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

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…
timday
  • 24,582
  • 12
  • 83
  • 135
11
votes
1 answer

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

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…
notifyroy
  • 139
  • 1
  • 8
10
votes
3 answers

boost: get the current local_date_time with current time zone from the machine

The problems is: I know how to get the local time in boost the code: boost::local_time::local_date_time currentTime( boost::posix_time::second_clock::local_time(), boost::local_time::time_zone_ptr()); std::cout <<…
Alek86
  • 1,489
  • 3
  • 17
  • 26
10
votes
3 answers

Is there a way to determine if a date/time does not exist?

Fun fact that I'm sure most of us who get to play in the time realms know - there are date/times that can appear valid but actually do not exist, e.g. 2:30 AM on a daylight savings switching time. Is there a way in C++ (standard or Windows) to…
dlanod
  • 8,664
  • 8
  • 54
  • 96
9
votes
1 answer

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

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,…
mavam
  • 12,242
  • 10
  • 53
  • 87
9
votes
2 answers

How to get the hour, minutes and seconds

const boost::posix_time::ptime now= boost::posix_time::second_clock::local_time(); year_ = now.date().year(); month_ = now.date().month(); day_ = now.date().day(); This is how I get the years, months and day out of boost::posix_time::ptime, but I…
Caesar
  • 9,483
  • 8
  • 40
  • 66
8
votes
1 answer

How do I convert a std::string to a boost::gregorian::date?

I'm trying to convert a std::string to a boost::gregorian::date like this: using namespace boost::gregorian; std::string str = "1 Mar 2012"; std::stringstream ss(str); date_input_facet *df = new date_input_facet("%e %b…
coredumped
  • 183
  • 2
  • 7
7
votes
1 answer

using from_string with boost date

I have the following code: #include #include #include #include #include #include #include…
itcplpl
  • 780
  • 4
  • 18
  • 29
1
2 3
8 9