如何创建类似世界时钟的应用程序
我想创建 iPhone 嵌入式“世界时钟”之类的应用程序。目前,我可以创建一个可以显示当前设备时间的单个时钟(模拟时钟)。
在这里,我用来
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:[NSDate date]];
检索当前的日期/时间。基于此 NSDate 对象的模拟时钟逻辑。
问题是,如何将一个国家/地区(澳大利亚、英国...)的日期/时间转换为这种 NSDate 格式?
---------- 而且,当我 NSLog 时(@"%@", [NSDate 日期]);它给出的是 Grin-witch 时间,而不是当前模拟器时间 ---------
I want to create iPhone embedded "World Clock" like application. At the moment I am able to create a single clock (analog clock) which can display Current device time.
Here, I am using
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:[NSDate date]];
to retrieve the current Date/Time. Analog clock logic based on this NSDate object.
Problem is, How can I get Date/Time of a Country (Australia, UK ...) on to this NSDate format?
---------- and also, When I NSLog(@"%@", [NSDate date]); it gives Grin-witch time, Not the current Simulator time ---------
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将时间转换为您需要的区域设置,请参阅此答案以了解如何执行此操作,
NSDate 休息 5 小时
You need to convert the time to whichever locale you need, see this answer for how to do that,
NSDate is 5 hours off
通过使用
NSCalendar
&NSTimeZone
,可以获取日期/时间,下面的代码片段展示了如何获取伦敦当前的日期/时间。你可以使用这个名为 SmileClock 的库来实现这一切。
By using the
NSCalendar
&NSTimeZone
, you can get the Date/Time, blew code snippet show how to get the current Date/Time in London.You can use this library called SmileClock achieve all.