如何获取指定时区的时间 [英] How to get a time for specified time zone
本文介绍了如何获取指定时区的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我正在使用Visual Stdio 2008并制作基于MFC的对话框应用程序.
我正在尝试制作世界时钟,我想获取具有指定时区的时间和日期,或者正在寻找解决方案以将格林尼治标准时间转换为另一个时区.
我使用gmtime_s()来获取GMT并据此进行计算,但我认为这并不明智.
有谁知道好的解决方案?
Hello,
I''m using Visual Stdio 2008 and making MFC based dialog application.
I''m trying to make world clock and I want to get time and date with specified time zone, or looking for solution to convert from GMT to another time zone.
I used gmtime_s() to get GMT and calculate from that but it is not smart I think.
Does anyone know good solution?
推荐答案
本文创建了一个项目,可以满足您的需求.
只需查看服务器部分即可:将其转换为本地时间需要花费UTC时间.
时区类和数据 [
Hi,
This article had made a project to make the thing you are looking for.
Just look at the server part : it take a UTC time to convert it to local time.
Time zone class and data[^]
Hope this helps.
请参见此处 [^ ]提供可用的时间功能.在内部,您的代码应始终在UTC中工作,这就是系统时钟的工作方式.当需要以人类可读的形式显示时间时,应使用适当的功能,该功能将根据当前选择的时区进行调整.
See here[^] for the time functions available. Internally your code should always work in UTC which is how the system clock operates. When you need to display a time in human readable form then you should use the appropriate function which will adjust according to the currently selected timezone.
这篇关于如何获取指定时区的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文