您可以在viewDidLoad方法
NSDate* currentDate = [NSDate date];
NSTimeZone* currentTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSTimeZone* nowTimeZone = [NSTimeZone systemTimeZone];
NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:currentDate];
NSInteger nowGMTOffset = [nowTimeZone secondsFromGMTForDate:currentDate];
NSTimeInterval interval = nowGMTOffset - currentGMTOffset;
NSDate* nowDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:currentDate];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE"];
NSString *dayName = [dateFormatter stringFromDate:nowDate];
NSString *timing = @"8:00am - 6:00pm";
NSString *description [email protected]"Today's Hours are";
NSArray *days = @[@"Monday",@"Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday",@"Sunday",];
for (NSString *str in days) {
if ([str isEqualToString:@"Saturday"]) {
timing = @"9:00am - 2:00pm";
}
if ([str isEqualToString:@"Sunday"]) {
description = @"Sorry we are closed today";
timing = nil;
}
if ([str isEqualToString:dayName]) {
NSLog(@"%@ : %@ :%@",str,description,timing);
//here you can write yourLabelname.text =[NSString stringWithFormat:@"%@ : %@ :%@",str,description,timing];
}
}
使用此代碼這會給你根據當前日
你有什麼到目前爲止,結果如何呢? –