【发布时间】:2012-05-10 10:24:58
【问题描述】:
是否可以将日期名称添加到日期选择器? 例如表盘会显示:
(星期日)3 | 11 | 2012
有可能吗? 谢谢!
【问题讨论】:
-
你解决了吗?我也有同样的问题......
标签: iphone objective-c ios5 ios4
是否可以将日期名称添加到日期选择器? 例如表盘会显示:
(星期日)3 | 11 | 2012
有可能吗? 谢谢!
【问题讨论】:
标签: iphone objective-c ios5 ios4
我认为您不能将 DayName(例如星期日)与 Year-Month-Day 一起使用,直到您没有完全自定义,但您可以通过以下代码获取带有日期的日期,这可能会对您有所帮助。
在Xib中绑定以下两个IBOutlet。
并将方法 -(IBAction)GetDateWithDay 与 DatePicker 与 ValueChange 属性绑定
在.h文件中
IBOutlet UIDatePicker* datePicker;
IBOutlet UILabel* lblDate;
在 .m 文件中
-(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];
}
【讨论】:
阅读this document对你有帮助
【讨论】:
您可以使用选项 DD。 例如。
$.datepicker.formatDate('DD', new Date(2007, 1 - 1, 26));
希望这会对您有所帮助。 UI/Datepicker/formatDate
【讨论】: