0

I am trying to get time and date in my local timezone (UTC-3) from a string timestamp (ex "1612909488"). I was looking for a solution in C++ but each example or code i saw only got the time and date from timestamp without applying the local timezone. For example if the timestamp is "1612909488" then UTC time is 22:24:48 but I need it in my local timezone that is 19:24:48. How can I do that?

Thanks for your help.

Tomrod
  • 3
  • 3
  • `How can I do that?` Comes to mind - use `std::put_time("%z"` then parse the result as a number and then multiply by 60 and add that number to timestamp. – KamilCuk Feb 09 '21 at 22:32
  • Wait, are you searching for [localtime](https://en.cppreference.com/w/cpp/chrono/c/localtime) vs [gmtime](https://en.cppreference.com/w/cpp/chrono/c/gmtime)? – KamilCuk Feb 09 '21 at 22:41
  • See https://stackoverflow.com/questions/15957805/extract-year-month-day-etc-from-stdchronotime-point-in-c – Jeff Garrett Feb 10 '21 at 01:21
  • I don't understand the difference between localtime vs gmtime. For now the solution that works for me is take the timestamp and substract -3*3600 to the number (-3 for UTC). But I don't know if this is the best solution or if this is a bad practice. – Tomrod Feb 10 '21 at 16:08

0 Answers0