boost-date-time

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

左心房为你撑大大i 提交于 2019-11-29 11:12:59
问题 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 in a filename). Of course I can just replace the delimiting strings, but have a feeling that there's a nicer way to do this with date-time's formatting options. Is there such a way, and if so, how can I use it? 回答1: Use std::strftime, it is

Using boost parse datetime string: With single digit hour format

我只是一个虾纸丫 提交于 2019-11-28 10:32:26
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 parsing method. So I tried linux API stftime which sometimes give values on wrong parsing method. I had to abandon it and move to boost. Now coming on to boost I am using 1_64 version. According to the documentation here I could not find a way to parse single digit hour format. bool getepochtime(const std::string &str, const std::string &format,

How to get the current time zone?

只谈情不闲聊 提交于 2019-11-27 23:26:54
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. Tobu 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 , defined in terms of offset from UTC and not stable over time (there's a longer form that can include

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

佐手、 提交于 2019-11-27 04:23:34
问题 Is there some "standard" way or the best I can do is to compute it directly by subtracting from gregorian::date(1970,1,1) ? 回答1: time_t is the type used to hold time in seconds (typically epoch time). I'm guessing you are after epoch time, if so I'm not aware of any way in boost of actually getting epoch time directly, aside from the subtraction you have already. Once you have a time_duration (result of the subtraction), you can call total_seconds() on the duration and store that in time_t .

Using boost parse datetime string: With single digit hour format

馋奶兔 提交于 2019-11-27 03:39:19
问题 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 parsing method. So I tried linux API stftime which sometimes give values on wrong parsing method. I had to abandon it and move to boost. Now coming on to boost I am using 1_64 version. According to the documentation here I could not find a way to

How to parse date/time from string?

一曲冷凌霜 提交于 2019-11-26 18:33:43
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" (optional layout) "23.09.2004 04:12:21" (german format, optional) "2003-02-11" (time may be missing) Needed Output : Seconds since Epoch (1970/01/01 00:00:00) or some other fixed point. Bonus : Also, reading the UTC-offset of the local system time would be great. The input is assumed to be a local time on the machine in question. The output needs to be

How to parse date/time from string?

旧巷老猫 提交于 2019-11-26 06:28:18
问题 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\" (optional layout) \"23.09.2004 04:12:21\" (german format, optional) \"2003-02-11\" (time may be missing) Needed Output : Seconds since Epoch (1970/01/01 00:00:00) or some other fixed point. Bonus : Also, reading the UTC-offset of the local system