天天看點

iOS開發---擷取目前日期是星期幾

+ (NSString *)currentDateWithFormatter:(NSString *)formatter

{

    NSDate *date = [NSDate date];

    NSDateFormatter *dateformatter = [[NSDateFormatteralloc] init];

    [dateformatter setDateFormat:formatter];

    NSString *weekString = [dateformatter stringFromDate:date];

    return weekString;

}

當給formatter指派為 @"EEEE"時,列印出來的weekString即為想要擷取的目前星期數(英文)

主要做法還是在時間格式那裡.隻不過是擷取目前日期而已

擷取日期時則把formatter指派為@"yyyy-MM-dd HH:mm"就可以了

繼續閱讀