【发布时间】:2010-03-08 10:47:11
【问题描述】:
对于那些熟悉 Excel 的人,我正在尝试在 Cocoa 中使用类似的 NETWORKDAYS 函数。
谁能帮助我构建一个 NSDate 类别所需的信息类型,该类别只能给我两个日期之间的工作日?
非常感谢 尼克
【问题讨论】:
对于那些熟悉 Excel 的人,我正在尝试在 Cocoa 中使用类似的 NETWORKDAYS 函数。
谁能帮助我构建一个 NSDate 类别所需的信息类型,该类别只能给我两个日期之间的工作日?
非常感谢 尼克
【问题讨论】:
我知道我给的不是优化的,但它只是给你一个探索的方式。 您可以像这样使用 NSCalendar 和 NSDateComponents:
// Date of today
NSDate *today = [NSDate date];
// init the gregorian calendar
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// Retrieve the NSDateComponents for the current date
NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:today];
// Number of the day in the week (e.g 2 = Monday)
NSInteger weekday = [weekdayComponents weekday];
(见Calendars, Date Components, and Calendar Units)
从那里你从你的第一个日期开始,你每天重复这个直到你的结束日期,并使用工作日你可以确定这一天是否在周末。 (我重复了那不是优化但它只是一个轨道)
【讨论】: