Converting NSDate from a calendar to another

送分小仙女□ 提交于 2019-12-06 06:04:37

An NSDate object represents a moment in time, irrespective of any calendar, time zone, or relativity (this last one is generally considered to be a non-issue in Earth-based computer science.)

When you create an instance of NSDate through any means, it is stored as simply the number of seconds since a fixed point in time (12:00 AM GMT on January 1, 2001 in the case of iOS and OS X.)

As a result, converting a date from Gregorian to Hijri doesn't do anything because that fixed moment remains the same.

If you tell us specifically what transformation you expect to occur between Gregorian and Hijri that is not already occurring, we can suggest an alternate course of action.

You don't have to make any conversions at all.

NSLog prints object's description method. Since NSDate stores only amount of seconds since reference date and does not keep a track of calendar it belongs to, it uses Gregorian calendar to format date for description method.

Customize NSDateFormatter to use your calendar and use stringFromDate: to get localized string value for your date.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!