在 Objective-c 中获取日期和时间
我想在我的应用程序中使用三个标签,第一个显示时间,第二个显示日期,第三个显示月份。现在我知道如何使用 NSDate 和日期格式等获取当前日期,但是如何在另一天开始时更新这一天?几个月也一样吗? NSDate 显示现在是什么时间,但我想做一个数字时钟,我该怎么做呢?提前致谢!
I'd like to have three labels in my application, the first shows the time, the second shows the day and the third shows the month. Now I know how to get the current date with NSDate and date formats and all, but how can I update the day when another day begins? And the same with months? And NSDate shows what time it is, but I'm looking to do a digital clock, how would I go on about that? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题非常广泛,这样的问题已经被问过很多次了。
就像这里-> 如何在 iPhone 中创建一个包含小时和秒的自定义图像的数字时钟
和此处 -> iPhone 数字时钟
这是有关如何为 iOS 创建模拟时钟的教程 -> http://iphone-dev- Tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html
Your question is really broad and questions like this have been asked on S.O. many times.
like here -> how to create a digital clock with custom images for hours and seconds in iphone
and here -> iPhone Digital Clock
Here is a tutorial on how to create an analog clock for iOS -> http://iphone-dev-tips.alterplay.com/2010/03/analog-clock-using-quartz-core.html
我不知道您的系统是否遵循 POSIX 标准,但如果遵循,您可能会考虑使用 gettimeofday 系统调用以及 localtime 和 < em>strftime 标准库函数。它们有 C API,应该可以由 Objective-C 代码调用,而且很可能您可能有更高级别的库调用。
I don't know if your system follow POSIX standards, but if it does you might consider using the gettimeofday system call and the localtime and strftime standard library functions. They have C APIs and should be callable by Objective-C code, and very probably you might have higher level library calls.