Converting Time Zones To Central Standard Time (CST) Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

Converting Time Zones To Central Standard Time (CST)

Post by Everydaydiesel »

I seem to be going in circles here and I would greatly appreciate any help I can get.


I have a date that comes in as "2019-05-16T09:30:00-04:00" as an example. (I wont know the timezone in advance)

In the example above it is -4:00 from UTC

2019-05-16 09:30:00 - 04:00

According to this chart https://savvytime.com/converter/utc-to-cst
adding 4 hours to 09:30:00 gives me 13:30 (or 8:30 AM converted to cst)


My question is how do I get the incoming date to the actual CST time.

Code: Select all

const char *time_details = "2019-05-16T09:30:00-04:00";
struct tm tm2;
strptime(time_details, "%Y-%m-%dT%H:%M:%S%z", &tm2);
time_t tmIncomingTime = mktime(&tm2);
struct tm * tmLocalTime = localtime(&tmIncomingTime);
time_t t3 = mktime(tmLocalTime);
The output of t3 is 9:30 which is not what I am expecting.

How can I get this converting the timezones with the correct time.

Thanks in advance.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Converting Time Zones To Central Standard Time (CST)

Post by doublemax »

Code: Select all

    wxDateTime dt;
    dt.ParseFormat("2019-05-16T09:30:00-04:00", "%Y-%m-%dT%H:%M:%S%z");
    wxLogMessage( "Local: %s", dt.FormatISOCombined() );
    dt.MakeUTC();
    wxLogMessage( "UTC:   %s", dt.FormatISOCombined() );
Use the source, Luke!
Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

Re: Converting Time Zones To Central Standard Time (CST)

Post by Everydaydiesel »

Thank you!!!
Post Reply