In most of the example I had seen,
time_zone_ptr zone( new posix_time_zone("MST-07") );
But, I just want to get the current time zone for my running machine. I do not want to hard code the time zone name.
May I know how can I do so in boost?
In most of the example I had seen,
time_zone_ptr zone( new posix_time_zone("MST-07") );
But, I just want to get the current time zone for my running machine. I do not want to hard code the time zone name.
May I know how can I do so in boost?
Well, maybe you could do it using the GeoIP library. I know it's a bit of an overkill, but since most computers in the world are connected to the internet, you could probably get away with it. According to the guy I'm developing for, it's been over 99% accurate.
Note: This is a dumb idea. I am just stretching for answers.
I am also looking for a solution to this problem, and my research hasn't turned up much, but it did turn up your question.
The closest thing to an answer I have found is an (undocumented, it seems) Boost class. It provides a way of converting from local time to UTC. There's an example of its usage (the only place it appears in the documentation AFAICT). I have not yet discovered a way of creating the actual posix_time_zone
object for the local time, which is what I really need. I also need one for UTC, but that I think I can figure out by just hardcoding the string.
Plain posix: call tzset, use tzname.
#include <ctime>
tzset();
time_zone_ptr zone(new posix_time_zone(tzname));
time_zone_ptr zone(new posix_time_zone(localtime(0)->tm_zone));