p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c91b13}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #6122ae}span.s3 {font-variant-ligatures: no-common-ligatures; color: #c32275}span.s4 {font-variant-ligatures: no-common-ligatures; color: #539aa4}span.s5 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s6 {font-variant-ligatures: no-common-ligatures; color: #000000}
- (NSString *)timeFormat
{
NSDate *selected = [self.datePickerView date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// [dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss-EEEE"];
NSString *currentOlderOneDateStr = [dateFormatter stringFromDate:selected];
return currentOlderOneDateStr;
}
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}
2016-12-01T20:11:04-Thursday替換為p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font: 18.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}
12****月****01****日****(****星期四****)20****點(diǎn)
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c91b13}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #6122ae}span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s4 {font: 18.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}span.s5 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s6 {font-variant-ligatures: no-common-ligatures; color: #0435ff}span.s7 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s8 {font-variant-ligatures: no-common-ligatures; color: #1d9421}span.s9 {font-variant-ligatures: no-common-ligatures; color: #c91b13}span.s10 {font: 18.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #c91b13}span.s11 {font-variant-ligatures: no-common-ligatures; color: #c32275}
-(NSMutableString*)weekdayStringFromDate:(NSString *)inputString {
//11月26日 (星期六) 15點(diǎn)
NSString * englishStr = [inputString substringFromIndex:20];
NSRange monthRange =NSMakeRange(5,2) ;//{5,2}
NSString * monthStr = [inputString substringWithRange:monthRange];
NSRange dayRange =NSMakeRange(8,2) ;
NSString * dayStr = [inputString substringWithRange:dayRange];
NSRange hourRange =NSMakeRange(11,2) ;
NSString * hourStr = [inputString substringWithRange:hourRange];
NSMutableString * weekday = [[NSMutableString alloc] initWithString:monthStr];
[weekday appendString:@"月"];
[weekday appendString:dayStr];
[weekday appendString:@"日"];
[weekday appendString:[NSString stringWithFormat:@"%@點(diǎn)",hourStr]];
NSArray *weekdays = [NSArray arrayWithObjects: @"星期天", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];
if ([englishStr isEqualToString:@"Wednesday"]) {
[weekday insertString:[NSString stringWithFormat:@"(%@)",weekdays[3]] atIndex:6];
return weekday;
}else if ([englishStr isEqualToString:@"Thursday"]){
[weekday insertString:[NSString stringWithFormat:@"(%@)",weekdays[4]] atIndex:6];
return weekday;
}else if ([englishStr isEqualToString:@"Friday"]){
[weekday insertString:[NSString stringWithFormat:@"(%@)",weekdays[5]] atIndex:6];
return weekday;
}else if ([englishStr isEqualToString:@"Saturday"]){
[weekday insertString:[NSString stringWithFormat:@"(%@)",weekdays[6]] atIndex:6];
return weekday;
}else if ([englishStr isEqualToString:@"Sunday"]){
[weekday insertString:[NSString stringWithFormat:@"(%@)",weekdays[7]] atIndex:6];
return weekday;
}else if ([englishStr isEqualToString:@"Monday"]){
[weekday insertString:[NSString stringWithFormat:@"(%@)",weekdays[8]] atIndex:6];
return weekday;
}else if ([englishStr isEqualToString:@"Tuesday"]){
[weekday insertString:[NSString stringWithFormat:@"(%@)",weekdays[9]] atIndex:6];
return weekday;
}
else{
return nil;
}
}
我在使用中總是碰到需要一些特殊的要求的 但是發(fā)現(xiàn)模擬器上面是英文的 我自己花時(shí)間去把這個(gè)英文換成中文,最后發(fā)現(xiàn) 原來(lái) ios 的系統(tǒng)是自帶了星期的,只是英文在模擬器的設(shè)置上面通用語(yǔ)言默認(rèn)是英文的,所以不顯示中文罷了,我通過(guò)對(duì)p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}
UIDatePickerMode的進(jìn)一步了解,發(fā)現(xiàn)如下幾種情況:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}
UIDatePickerModeTime:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}
UIDatePickerModeDate:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}
UIDatePickerModeDateAndTime:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}
UIDatePickerModeCountDownTimer:
![Upload 屏幕快照 2016-12-01 下午1.55.38.png failed. Please try again.]
最后給大家推薦一個(gè)很好的 demo鏈接:http://www.code4app.com/thread-6702-1-1.html