美文网首页
根据输入的时间获取当天是星期几

根据输入的时间获取当天是星期几

作者: 丶小裤头灬 | 来源:发表于2018-01-11 15:49 被阅读85次

    直接上代码:

    - (void)viewDidLoad {  
        [super viewDidLoad];  
          
        NSLog(@"this day is %@", [self getTheDayOfTheWeekByDateString:@"2015-12-18"]);  
      
        // Do any additional setup after loading the view, typically from a nib  
          
    }  
    ///根据用户输入的时间(dateString)确定当天是星期几,输入的时间格式 yyyy-MM-dd ,如 2015-12-18  
    -(NSString *)getTheDayOfTheWeekByDateString:(NSString *)dateString{  
          
        NSDateFormatter *inputFormatter=[[NSDateFormatter alloc]init];  
          
        [inputFormatter setDateFormat:@"yyyy-MM-dd"];  
          
        NSDate *formatterDate=[inputFormatter dateFromString:dateString];  
          
        NSDateFormatter *outputFormatter=[[NSDateFormatter alloc]init];  
          
        [outputFormatter setDateFormat:@"EEEE-MMMM-d"];  
          
        NSString *outputDateStr=[outputFormatter stringFromDate:formatterDate];  
          
        NSArray *weekArray=[outputDateStr componentsSeparatedByString:@"-"];  
          
        return [weekArray objectAtIndex:0];  
    }  
    

    相关文章

      网友评论

          本文标题:根据输入的时间获取当天是星期几

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