Get datetime in my timezone
-
QDateTime::toTimeSpec has an example.
-
QDateTime::toTimeSpec has an example.
@SGaist But still can't see where I would set the time zone I want in order to do the conversion. For example if someone who is using my app is in China, I need to convert his local time to my local time because China is several hours ahead of my local time. China is 7 hours, if I am not mistaken, ahead, so if a user is using my app there and it is 20:21 there I need the app to update to database the time 11:21.
For the time being I am using www.timeapi.io api to get time I need. -
The use QDateTime::toTimeZone() - it's even mentioned in toTimeSpec()
-
The use QDateTime::toTimeZone() - it's even mentioned in toTimeSpec()
@Christian-Ehrlicher Thanks, exactly what I needed, my eyes went only for the code, didn't even see
QDateTime::toTimeZone()
.Is there any chance, if you know, that this might not work correctly or it being unreliable when compared to the timeapi.io api?
-
What kind of unreliability are you expecting ?
-
@SGaist like for example if the user has its system time wrong, wouldn't that convert to a wrong time also.
@hbatalha said in Get datetime in my timezone:
like for example if the user has its system time wrong, wouldn't that convert to a wrong time also.
Nice joke... how is any program supposed to do a correct conversion then?
-
If you are worried about that kind of issue you should do the work server side. Provided that your server time is accurate.
-
@hbatalha said in Get datetime in my timezone:
like for example if the user has its system time wrong, wouldn't that convert to a wrong time also.
Nice joke... how is any program supposed to do a correct conversion then?
@Christian-Ehrlicher hahaha I don't know, I always find myself going to the worst case scenarios.
And also, from time to time my Windows 10 system time changes by itself(always one hour ahead) whether it is set automatically or not and that is an issue many users complain about. So that one thing I am worried about.
-
If you are worried about that kind of issue you should do the work server side. Provided that your server time is accurate.