5

是否可以将日期名称添加到日期选择器?例如拨号将显示:

(星期日)3 | 11 | 2012

有可能吗?谢谢!

4

4 回答 4

4

I think you can not DayName(eg. Sunday) with Year-Month-Day until you not make it totally custom but you can get the day with date by following code may be It will help you.

Bind following two IBOutlet in Xib.

and bind method -(IBAction)GetDateWithDay with DatePicker with ValueChange attribut

in .h file

IBOutlet UIDatePicker* datePicker;
IBOutlet UILabel* lblDate;

in .m file

-(IBAction)GetDateWithDay
{

     NSDate* dt = datePicker.date;
     NSDateFormatter* df = [[[NSDateFormatter alloc]init]autorelease];
     [df setDateFormat:@"yyyy-MM-dd"];

     NSCalendar *calendar = [NSCalendar currentCalendar];
     NSInteger units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit;
     NSDateComponents *components = [calendar components:units fromDate:dt];
     NSInteger year = [components year];
     NSInteger day = [components day];

     NSDateFormatter *weekDay = [[[NSDateFormatter alloc] init] autorelease];
     [weekDay setDateFormat:@"EEEE"];

     NSDateFormatter *calMonth = [[[NSDateFormatter alloc] init] autorelease];
     [calMonth setDateFormat:@"MM"];

     lblDate.text = [NSString stringWithFormat:@"%@, %i-%@-%i",[weekDay stringFromDate:dt], day, [calMonth stringFromDate:dt], year];

}

于 2012-05-10T11:30:48.153 回答
0

看看这段代码:

http://code4app.net/ios/FlatDatePicker/51cce1d76803fa4b0c000003

http://code4app.net/ios/Custom-DatePicker/51f667d36803fab73f000001

希望这能解决你的问题

于 2014-01-10T11:04:45.340 回答
0

阅读此文档将对您有所帮助

于 2012-05-10T10:37:56.560 回答
-3

您可以使用选项 DD。例如。

$.datepicker.formatDate('DD', new Date(2007, 1 - 1, 26));

希望这会帮助你。UI/日期选择器/formatDate

于 2012-05-10T10:44:10.850 回答