当用户从日期选择器中选择日期时,如何在下拉列表中获取特定的一周?

时间:2012-09-04 10:40:55

标签: iphone ios ios5 ios4

当用户从日期选择器中选择日期时,如何从下拉列表中获取一周中的特定日期?

我想让用户选择日期drom datepicker。在下一个按钮中,我有一个日期字段,其中包含一周内的日期列表。

我想在用户点击日期按钮时显示datepicker中所选日期的特定日期。 Plz帮帮我?????

2 个答案:

答案 0 :(得分:2)

试试这个

NSDate *today=calendarPicker.date;

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *components = [gregorian components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate: today];

components.year = [textfield.text intValue]; // Here value for year is fetched from a text field control. Similarly other values like month, date, hour or minute can be changed.

[calendarPicker setDate: [calendar dateFromComponents:components] ]; // Update the date picker control.

[calendar release];

答案 1 :(得分:1)

此链接描述了如何使用日期时间选择器。对不起,以前的回答是针对其他语言的

http://www.dosomethinghere.com/2010/11/21/iphone-date-and-time-picker-view/