我正在从 coredata 获取日期并尝试获取该日期的工作日。我尝试了以下代码,但它不起作用。
NSDateFormatter *weekDayFormatter = [[NSDateFormatter alloc]init];
[weekDayFormatter setDateFormat:@"EEEE"];
NSDate *weekDay = [results valueForKey:@"date"];
NSLog(@"%@",weekDay);//This log is working.
NSString *weekDayString = [weekDayFormatter stringFromDate:weekDay];
NSLog(@"%@",weekDayString); //This log is displaying null.
NSLog(@"%@ is spent on %@",[results valueForKey:@"amount"],weekDayString);
如果我使用[NSDate date]
而不是[results valueForKey:@"date"]
.