根據 long long 型別的時間戳,來判斷為 周幾
阿新 • • 發佈:2019-01-26
寫專案過程中,遇到一個問題,要求我把一個時間戳給顯示為周幾的樣式, 百度了一下,完成之後就寫一個部落格記錄下來. 下面是程式碼
+ (NSString *)getWeekDayFordate:(long long)data
{
NSArray *weekday = [NSArray arrayWithObjects: [NSNull null], @"週日", @"週一", @"週二", @"週三", @"週四", @"週五", @"週六", nil];
NSDate *newDate = [NSDatedateWithTimeIntervalSince1970:data];
NSCalendar
NSDateComponents *components = [calendar components:NSWeekdayCalendarUnit fromDate:newDate];
NSString *weekStr = [weekday objectAtIndex:components.weekday];
return weekStr;
}