获得一个不同的时区的时间,使用C ++ [英] Getting current time of a different timezone using C++
本文介绍了获得一个不同的时区的时间,使用C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何获得一个不同的时区的当前时间?例如,我需要知道在新加坡当前的时间,其中作为我的系统设置为PT时间。
How do i get the current time of a different time zone? Example, i need to know the current time in Singapore where as my system is set to PT time.
推荐答案
一个实现是使用时间
来得到当前UTC时间,然后操纵 TZ
环境变量到目的地时区。然后使用则localtime_r
转换到时区的本地时间。
One implementation would be to use time
to get the current time in UTC and then manipulate the TZ
environment variable to your destination timezone. Then use localtime_r
to convert to that timezone's local time.
这篇关于获得一个不同的时区的时间,使用C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文