獲取當前時間(美國時間) NSDate *dateToDay = [NSDate date]; NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-DD HH:mm:ss"]; NSLocale *local = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; [df setLocale:local]; NSString *myDataString = @"2009-09-15 18:30:00"; 字符串生成日期的代碼 NSDate *myData = [df dateFromString:myDataString]; 日期比較 switch ([dateToDay compare:myData]) { case NSOrderedSame: NSLog(@"These dates are the same!"); break; case NSOrderedAscending: NSLog(@"dateToDay is earlier than myDate!"); break; case NSOrderedDescending: NSLog(@"mydate is earlier than dateToDay"); break; default: NSLog(@"Bad times. Invalid enum value returned."); break; }
新聞熱點
疑難解答