c ++ localtime更改时区 [英] c++ localtime when changing timezone

查看:987
本文介绍了c ++ localtime更改时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置工作使用localtime()来获得一个tm与其中表示的本地时间。

I have a setup working using localtime() to get a tm with the local times represented in it. And that is all good.

但是,如果我在应用程序运行时更改时区,则不会注意到我更改了时区。

However, if I change timezone while the application is running, it does not notice that I have changed timezones.

有没有办法让它再次去看刷新到系统时区?

Is there some way to tell it to 'go look again' to refresh to the system timezone?

我知道这可能不是

推荐答案

没有什么可以用来测试这个功能,标准库来做到这一点。除非您的平台为库更新时区提供一些扩展,否则程序调用 localtime()可能总是使用在程序启动时处于活动状态的时区。

There's nothing in the standard library to do this. Unless your platform offers some extension to the library for updating the time zone, your program's calls to localtime() will probably always use the time zone that was active at program start up.

您可以通过将 localtime 文件放在一个单独的进程中,您的主程序可以启动和关闭,从而重新初始化该进程的时区。

You could probably work around that by putting the localtime stuff in a separate process that your main program can startup and shutdown at will, thus re-initializing that process's time zone.

或者您的平台可能提供一些其他API来获取本地时间,反映系统时间的变化区域。

Or instead your platform may offer some other API for getting the local time that will reflect changes in the system time zone.

这篇关于c ++ localtime更改时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆