美文网首页
系统自带的时间替换

系统自带的时间替换

作者: 灰客 | 来源:发表于2016-11-30 20:15 被阅读0次

    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****点

    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点
    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:@"%@点",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;
    }
    

    }

    我在使用中总是碰到需要一些特殊的要求的 但是发现模拟器上面是英文的 我自己花时间去把这个英文换成中文,最后发现 原来 ios 的系统是自带了星期的,只是英文在模拟器的设置上面通用语言默认是英文的,所以不显示中文罢了,我通过对p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}

    UIDatePickerMode的进一步了解,发现如下几种情况:

    屏幕快照 2016-12-01 下午1.53.12.png

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}

    UIDatePickerModeTime:


    屏幕快照 2016-12-01 下午1.53.57.png

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}

    UIDatePickerModeDate:


    屏幕快照 2016-12-01 下午1.54.33.png

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}

    UIDatePickerModeDateAndTime:


    屏幕快照 2016-12-01 下午1.55.05.png

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

    最后给大家推荐一个很好的 demo链接:http://www.code4app.com/thread-6702-1-1.html

    相关文章

      网友评论

          本文标题:系统自带的时间替换

          本文链接:https://www.haomeiwen.com/subject/mhitmttx.html