Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust Time to Daylight Saving for localtime C++

Tags:

c++

linux

I have a piece of optimized function to get the GMT time. I would like to convert it to local time. I would want to call localtime and gmtime function only once to adjust the time to localtime as calling localtime and gmtime multiple times would defeat the purpose of using the optimized function. My idea is adding the difference in time zone to the GMT time I obtained. However, my problem is how could I adjust my localtime when there is daylight saving? Any ideas on checking that?

Thanks.

like image 819
Steveng Avatar asked Nov 15 '22 06:11

Steveng


1 Answers

You could use TZ database that is stored most of the time in /usr/share/lib/zoneinfo in most linux distributions. This database manages daylight saving so you do not nees to deal with that.

like image 188
Amine Kerkeni Avatar answered Dec 17 '22 02:12

Amine Kerkeni