Daylight saving time of current tz
in my c++ software I've used Boost in some parts and also for the开发者_开发知识库 local time. OK, now my problem is to make a check if in my machine is active or not the DST.
With the follow part of code I can know only the difference from the UTC time. In my case the difference is 2 hours because is active the DST
ptime tLoc = second_clock::local_time();
ptime tUTC = second_clock::universal_time();
time_duration tDiff = tUTC - tLoc;
local_time_zone = tDiff.hours();
I think that the boolean funcion has_dst() can help, right?
My system is Debian GNU/Linux.
Thanks
Look at plain C functions in time.h/ctime
localtime will return a struct tm*
struct tm has as its last field a flag telling if it is under DST or not.
I believe the function you are looking for is local_date_time_base<>::is_dst()
. All date_time data types in Boost.DateTime are derived from local_date_time_base<>
. The following should give you the required result:
namespace lt = boost::local_time;
// for example, use central time zone
lt::time_zone_ptr zone(new lt::posix_time_zone(
"CST-06:00:00CDT+01:00:00,M3.2.0/02:00:00,M11.1.0/02:00:00"));
lt::local_date_time tloc = lt::local_sec_clock::local_time(zone);
std::cout << "I'm " << (tloc.is_dst() ? "" : "not ") << "in DST";
精彩评论