0

I have a string timestamp ("YYYY-MM-DD HH:MM:SS") which is in GMT and I need to make a wxDateTime from it. Since with wxDateTime, (as stated in the documentation) "the time is always stored internally in GMT", one would presume there is a straightforward way to do this bypassing time zone altogether but "all wxDateTime constructors and setters which take the broken down date assume that these values are for the local time zone". So is it possible? Failing that, what is the easiest way to perform the above said conversion?

Ivan
  • 317
  • 1
  • 4
  • 8
  • 1
    [wxDateTime::ParseISOCombined()](https://docs.wxwidgets.org/trunk/classwx_date_time.html#a76a36f113100df4dd37f87385fbd9991) should store your string "as is". You can set the time zone later. – Ripi2 Nov 08 '22 at 20:33
  • 2
    I think the easiest thing is to just add the time zone to the string time stamp. For example, to "2022-11-08 11:00:00" append " -0000". Then calling [wxDateTime::ParseFormat](https://docs.wxwidgets.org/latest/classwx_date_time.html#aa2137ab606576e3f5baf50d98ff47d17) with the format string "%Y-%m-%d %H:%M:%S %z" should give you the date-time objects like what you want. – New Pagodi Nov 08 '22 at 20:34
  • Thanks for the answers. Turns out ParseISOCombined() is just a wrapper for ParseFormat() without time zone information and hence treats the input as local time. What New Pagodi has suggested indeed looks like the easiest way. If the input was a UNIX timestamp (not a string), wxDateTime(time_t) would do exactly what I wanted. – Ivan Nov 09 '22 at 13:00

0 Answers0