iphone - 日期选择器是否可以显示年/月/日 + 日名称?

标签 iphone objective-c ios5 ios4

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

(星期日)3 | 11 | 2012

有可能吗? 谢谢!

最佳答案

我认为你不能将 DayName(例如星期日)与 Year-Month-Day 一起使用,除非你完全自定义它,但你可以通过以下代码获取带日期的日期可能会对你有所帮助。

在Xib中绑定(bind)以下两个IBOutlet。

并将方法 -(IBAction)GetDateWithDayDatePickerValueChange 属性绑定(bind)

在.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];

关于iphone - 日期选择器是否可以显示年/月/日 + 日名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10532070/

相关文章:

View 中的 iOS 静态表?

iphone - 如何使用 iPhone SDK 创建 PDF 文档?

iphone - 滚动图像的巨大延迟

ios - 如何更改我的应用程序的 VoiceOver 发音?

objective-c - 保存时检测 NSManagedObject 的更改

iphone - 如何保存照片并在照片上叠加标签?

iphone - AQGridView 背景图片

iphone - "Failed to upload *.app on Device "iPhone 出现错误

iphone - 我的Xcode-编译错误只是显示红色的感叹号

objective-c - 将 Twitter 帐户添加到 ABRecordRef(人员)的最简单方法