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
6
votes
2 answers

how to parse a string with date-time + time offset to a boost::posix_time::ptime?

I have a string "2011-10-20T09:30:10-05:00" Does someone know how I can parse it with boost::date_time library?
Alek86
  • 1,489
  • 3
  • 17
  • 26
6
votes
2 answers

How to get GMT time in milliseconds using boost Date_Time?

Is there a simple way to get from boost Date_Time library a current GMT time in milliseconds? Here is one example which uses time_of_day, I don't want time_of_day but total time in GMT as long long int: boost::posix_time::ptime time = …
stefanB
  • 77,323
  • 27
  • 116
  • 141
6
votes
2 answers

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

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".
Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
6
votes
0 answers

boost::gregorian::date_duration conversion from days to months and days to years

I am trying to calculate the time between two boost::gregorian dates. Currently I am simply taking the difference of the two dates, giving me a date_duration to work with: boost::gregorian::date rhs(2000, 1, 1); boost::gregorian::date lhs(2005, 6,…
pje
  • 2,458
  • 1
  • 25
  • 26
6
votes
1 answer

Get year from boost ptime

I'm converting an existing program to C++ and here need to manipulate Sybase timestamps. These timestamps contain date and time info, which to my knowledge can be best handled by a boost::posix_time::ptime variable. In a few places in the code I…
pointer
  • 601
  • 7
  • 10
6
votes
1 answer

boost::date_time, g++-4.7.0, compile error

The following code gives compile error with g++-4.7.0 but compiles fine with g++-4.6. #include #include using namespace std; int main(){ boost::posix_time::ptime…
suresh
  • 1,109
  • 1
  • 8
  • 24
6
votes
1 answer

Getting current date from clock

I am doing this boost::gregorian::date current_date(boost::date_time::day_clock::local_day()); and I get the following error ‘template class boost::date_time::day_clock’ used without template parameters Anything that I have…
HelloWorld_Always
  • 1,555
  • 3
  • 22
  • 32
5
votes
1 answer

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

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 int _tmain(int argc, _TCHAR* argv[]) { // Print the current locale …
Flethuseo
  • 5,969
  • 11
  • 47
  • 71
5
votes
2 answers

Use boost date_time to parse and create HTTP-dates

I'm writing a kind of HTTP proxy, so I need to be able to do 3 things: Parse an HTTP-date given any of the 3 formats specified in RFC 2616, sec 3.3, Convert a file date-time to an HTTP-date string, and Output the date to a string. For reference,…
John Price
  • 101
  • 1
  • 7
5
votes
1 answer

Boost, how to parse following string to date/time

I have the following milli/micro second accuracy string to parse into some sort of boost datetime. std::string cell ="20091201 00:00:04.437"; I have seen documentation regarding facets. Something like this date_input_facet* f = new…
Ivan
  • 7,448
  • 14
  • 69
  • 134
5
votes
1 answer

unordered_map with gregorian dates

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…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
5
votes
1 answer

Getting month from boost date object

I have a boost::date object. When I call month() interface on the object it returns me the month the object is holding but in terms of a string. Is there a way I can get the number associated with the month? i.e date mySampleDate =…
Ricketyship
  • 644
  • 2
  • 7
  • 22
5
votes
2 answers

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

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()…
mathematician1975
  • 21,161
  • 6
  • 59
  • 101
4
votes
1 answer

Howto format a boost::date_time-object as per RFC 3339

I want to use the date_time library in boost to represent time in my application. This application will generate Atom feeds, which in turn mandates time-stamps in the format specified in RFC 3339, for example "1990-12-31T23:59:60Z" or…
Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
4
votes
1 answer

boost::gregorian::date with time?

So far it looks like boost::gregorian::date only has day/month/year. I need to also store hour/minute/second. Can this object handle both? I'm having difficulty understanding how to represent all of this data.
void.pointer
  • 24,859
  • 31
  • 132
  • 243
1
2
3
8 9