获取当前时间(美国时间) 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; }
新闻热点
疑难解答