我一直在为 iOS 开发一个日历应用程序,这让我遇到了很多问题。
我正在使用本地通知进行提醒。存储事件日期、警报日期或其他内容的最佳方式是什么?我的意思是,问题是由时区差异等引起的。我将事件存储在核心数据中。我一直在使用 NSDate 进行日期存储,但我不确定这是在日历 View 中查询和表示事件的好方法。由于时区的原因,事件出现在错误的日期(例如距真实日期的前 1 天)。
另外,是否有我可以查看的教程或开源项目?我没有遇到任何全面的东西,只有关于如何使用tapku 日历 View 的小教程。
编辑:我不是在问仅有关日历 View 的问题。我在询问日历应用程序的基础架构。
最佳答案
您应该使用 NSDate 存储,并使用 NSDateComponents 呈现。
Because of timezone, the events were showing up at wrong days (like 1 day before from real day).
发生这种情况是因为 NSDate 是一个绝对时间点。您需要根据用户区域设置进行适当的转换以显示。 NSDateComponents(连同 NSCalendar)会处理这个问题。
The Date and Time Programming Guide会告诉你所有你需要知道的,但第一段定下了基调:
There are three main classes used for working with dates and times.
- NSDate allows you to represent an absolute point in time.
- NSCalendar allows you to represent a particular calendar, such as a Gregorian or Hebrew calendar. It provides the interface for most date-based calculations and allows you to convert between NSDate objects and NSDateComponents objects.
- NSDateComponents allows you to represent the components of a particular date, such as hour, minute, day, year, and so on.
关于ios - 创建日历应用程序 : Time Storage and Representation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12363749/