0

我想从 UIDatePicker 以下格式显示选定的日期。这怎么可能?请帮帮我格式是:Sat Feb 23 3:42 PM

4

4 回答 4

2

这是您想要的输出的代码:

NSDate *chosen = [datePicker date];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEE MMM dd hh:mm a"];

NSString *formated_date  = [formatter stringFromDate:chosen];

NSLog(@"formated date is : %@", formated_date];

您可以通过阅读以下链接更改日期格式:http: //unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns

于 2013-02-23T14:46:48.527 回答
1
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ;   
NSDateComponents *components = [gregorian components:unitFlags fromDate:yourPickerDate];
 NSInteger yourWeekDay = [components weekday];

我想这会对你有所帮助。

于 2013-02-23T10:23:14.747 回答
1
NSDateFomatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormat:@"DDD MMM dd mm:ss aa"];
NSString *dateString = [dateFormatter stringFromDate:date];
于 2013-02-23T10:23:38.300 回答
0

我得到了它....

NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];

[dateFormat setDateFormat:@"EEE MMM dd hh:mm aa"];

NSLog(@"格式为:%@",[dateFormat stringFromDate:datePicker.date]);

于 2013-02-23T11:53:33.980 回答