从ipad获取日期信息

时间:2012-10-10 14:54:43

标签: ios xcode nsdate nsdatecomponents nsdatepicker

我们需要从IPad中获取实际日期并将其保存在变量中。我们搜索了NSDateComponents和NSDate,但我们还没有找到任何东西。 例如,如果今天是10月25日,我们希望有一个值为25的int和另一个10(10月)。

我们将不胜感激。 谢谢!!

1 个答案:

答案 0 :(得分:2)

What did you try

您至少阅读了Date and Time Programming Guide关于解释所有内容的主题吗?

文档中的清单5直接为您提供了答案

NSDateComponents *comps = [[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSMonthCalendarUnit) fromDate:[NSDate date]];
NSInteger day = [comps day];
NSInteger month = [comps month];