Start Nscalendar autoupdatingcurrentcalendar

Nscalendar autoupdatingcurrentcalendar

If someone uses it on the 29th of february on a leap year, february 18 years earlier will always be 28 days long.

The particular values of the unit are defined by each calendar, and are not necessarily consistent with values for that unit in another calendar.

NSTime Interval seconds Per Day = 24 * 60 * 60; NSDate *tomorrow = [[NSDate alloc] init With Time Interval Since Now:seconds Per Day]; NSDate *yesterday = [[NSDate alloc] init With Time Interval Since Now:-seconds Per Day]; [tomorrow release]; [yesterday release]; NSTime Interval seconds Per Day = 24 * 60 * 60; NSDate *today = [[NSDate alloc] init]; NSDate *tomorrow, *yesterday; tomorrow = [today date By Adding Time Interval: seconds Per Day]; yesterday = [today date By Adding Time Interval: -seconds Per Day]; [today release]; 如果要对NSDate对象进行比较,可以使用is Equal To Date:, compare:, later Date:和 earlier Date:方法。这些方法都进行精确比较,也就是说这些方法会一直精确比较到NSDate对象中秒一级。例如,你可能比较两个日期,如果他们之间的间隔在一分钟之内则认为这两个日期是相等的。在这种情况下使用,time Interval Since Date:方法来对两个日期进行比较。下面的代码进行了示例: 日历对象封装了对系统日期的计算,包括这一年开始,总天数以及划分。你将使用日历对象对绝对日期与date components(包括年,月,日,时,分,秒)进行转换。 NSCalendar定义了不同的日历,包括佛教历,格里高利历等(这些都与系统提供的本地化设置相关)。NSCalendar与NSDate Components对象紧密相关。 你可以通过NSCalendar对象的current Calendar方法来获得当前系统用户设置的日历。 NSCalendar *current Calendar = [NSCalendar current Calendar]; NSCalendar *japanese Calendar = [[NSCalendar alloc] init With Calendar Identifier: NSJapanese Calendar]; NSCalendar *users Calendar = [[NSLocale current Locale] object For Key: NSLocale Calendar]; NSDate Components *components = [[NSDate Components alloc] init]; [components set Day:6]; [components set Month:5]; [components set Year:2004]; NSInteger weekday = [components weekday]; // Undefined (== NSUndefined Date Component) NSDate *today = [NSDate date]; NSCalendar *gregorian = [[NSCalendar alloc] init With Calendar Identifier: NSGregorian Calendar]; NSDate Components *weekday Components = [gregorian components:(NSDay Calendar Unit | NSWeekday Calendar Unit) from Date:today]; NSInteger day = [weekday Components day]; NSInteger weekday = [weekday Components weekday]; NSDate Components *components = [[NSDate Components alloc] init]; [components set Weekday:2]; // Monday [components set Weekday Ordinal:1]; // The first Monday in the month [components set Month:5]; // May [components set Year:2008]; NSCalendar *gregorian = [[NSCalendar alloc] init With Calendar Identifier: NSGregorian Calendar]; NSDate *date = [gregorian date From Components:components]; NSDate Components *components = [[NSDate Components alloc] init]; [components set Month:11]; [components set Day:7]; NSCalendar *gregorian = [[NSCalendar alloc] init With Calendar Identifier: NSGregorian Calendar]; NSDate *birthday = [gregorian date From Components:components]; NSDate Components *comps = [[NSDate Components alloc] init]; [comps set Day:6]; [comps set Month:5]; [comps set Year:2004]; NSCalendar *gregorian = [[NSCalendar alloc] init With Calendar Identifier: NSGregorian Calendar]; NSDate *date = [gregorian date From Components:comps]; [comps release]; [gregorian release]; NSCalendar *hebrew = [[NSCalendar alloc] init With Calendar Identifier: NSHebrew Calendar]; NSUInteger unit Flags = NSDay Calendar Unit | NSMonth Calendar Unit | NSYear Calendar Unit; NSDate Components *components = [hebrew components:unit Flags from Date:date]; NSInteger day = [components day]; // 15 NSInteger month = [components month]; // 9 NSInteger year = [components year]; // 5764 NSDate *today = [[NSDate alloc] init]; NSCalendar *gregorian = [[NSCalendar alloc] init With Calendar Identifier: NSGregorian Calendar]; NSDate Components *offset Components = [[NSDate Components alloc] init]; [offset Components set Hour:1]; [offset Components set Minute:30]; // Calculate when, according to Tom Lehrer, World War III will end NSDate *end Of World War3 = [gregorian date By Adding Components:offset Components to Date:today options:0]; NSDate *today = [[NSDate alloc] init]; NSCalendar *gregorian = [[NSCalendar alloc] init With Calendar Identifier: NSGregorian Calendar]; // Get the weekday component of the current date NSDate Components *weekday Components = [gregorian components: NSWeekday Calendar Unit from Date:today]; /* Create a date components to represent the number of days to subtract from the current date.

object that describes the calendrical components required for the computation.

You can provide as many components as you need (or choose to).

To transition from the Julian calendar to the Gregorian calendar, 10 days were dropped from the Gregorian calendar (October 5–14).

After the Gregorian calendar was introduced, many countries continued to use the Julian calendar, with Turkey being the last country to adopt the Gregorian calendar, in 1926.

And now it works, thank youlet components = NSCalendar.current Calendar().components([.

Second], from Date: NSDate()) components.month -= 1 let date In The Middle Of Period = NSCalendar.current Calendar()From Components(components)!

always returns most recent version of system calendar.

That is important, when you are presenting data based on the various parameters of a calendar like number of days in a month, number of a weeks in year or number of hours in a day.

The app I implemented this in has been tested fairly extensively on a number of devices; no crashes yet.. In your implementation, if the user is under 18, the interface will force them to lie about their birth date.