GMT to local time

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
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

GMT to local time

Post by cutecode »

I get date and time values from a web server.
I converted thees values to wxDateTime, but this server returns dates in GMT.

How to convert those values to my local time?
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: GMT to local time

Post by PB »

Was there any issues with methods described in the section Time Zone and DST Support of wxDateTime docs?

Edit
I did not really test it but something like this may work

Code: Select all

      
       // this pretends to be the datetime from the server in the UTC        
        wxDateTime dtUTC = wxDateTime::Now(); 

        // calc the difference between the UTC and the local tz
        wxTimeSpan ts = dtUTC.Subtract(dtUTC.ToUTC()); 

        // now offset the datetime by the difference
        wxDateTime dtLocal = dtUTC + ts;
Please notice the word "may", these things can get tricky. IIRC there was a timezone related bug in wxWidgets not that long ago, but I may be confusing it with something else...
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: GMT to local time

Post by cutecode »

yes, this code works OK.
+3 hours (Moscow time)

Thank you VERY MUCH
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
Post Reply