Tag: nsdate

如何按升序对string中包含date的数组进行sorting

我有字典数组,每个字典中都包含一个date参数。 date参数数组(包含在字典中)如下: [@"16-1-2015 7:00PM",@"15-1-2014 11:30AM",@"14-1-2014 7:00PM", @"15-1-2015 6:30AM ".@"16-1-2015 8:30PM"] 我需要输出: [@"16-1-2015 8:30PM",@"16-1-2015 7:00PM",@"15-1-2015 6:30AM ", @"15-1-2014 11:30AM",@"14-1-2014 7:00PM"];

谷歌压光机API的date格式化程序

1)我从谷歌日历获取date。 格式为2013-05-03T22:30:00.000 + 02:00 。 在应用中使用哪种date格式。 2)我必须显示2013年2月4日这种格式的date。 如何在我的应用程序中实现这两个function? 请帮帮我。 谢谢。

按照NSDatesorting表格部分

如何sortingNSDate ,使得如果date的时间是星期天早上的05:00,那么它将在星期六“晚上”停留,但最后在列表中? 我按date从JSON数据sorting我的tableview部分 [[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"fodboldStream", @"command", nil] onCompletion:^(NSDictionary *json) { //got stream //NSLog(@"%@",json); [[API sharedInstance] setSoccer: [json objectForKey:@"result" ]]; games = [json objectForKey:@"result"]; sections = [NSMutableDictionary dictionary]; for (NSDictionary *game in games) { NSNumber *gameType = game[@"dato"]; NSMutableArray *gamesForType = sections[gameType]; if (!gamesForType) { gamesForType = [NSMutableArray array]; sections[gameType] = gamesForType; } [gamesForType […]

NSString转换为NSDate失败

我有以下代码 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/YYYY HH:mm"]; NSString *dateString = @"10/27/2012 18:00"; NSDate *parsedDate = [dateFormatter dateFromString:dateString] ; NSLog(@"Parsed Date.. %@",[parsedDate description]); 我得到NSLog语句为Parsed Date.. 2011-12-25 00:00:00 +0000 。 我将不胜感激任何帮助解决这个问题。 我只是想将该NSString转换为其NSDate等价物。 尝试使用NSTimeZone以及,但没有效果。 我在这里错过了什么?

在NSOrderedAscending和NSOrderedDescending的特定范围内的date

我有这个代码: NSComparisonResult compareStart = [firstDate compare: dateSelected]; NSComparisonResult compareEnd = [secondDate compare: dateSelected]; if (((compareStart == NSOrderedAscending) || (compareStart == NSOrderedSame)) && (compareEnd == NSOrderedDescending)) 但它不进入“如果”当firstDate = dateSelected或secondDate = dateSelected …为什么?

如何查询和转换Parse.comdate到NSDate /string

我想把parsing列“ createdAt ”,查询它,并把它变成一个string,在UI上显示为一个标签,以显示用户何时发布产品和何时过期。 在stackoverflow上也有类似的问题,但没有人帮助我,所有的都给了我错误和崩溃。 我正在使用一个TableViewController类,我查询2件事情: timeCreated和timeCreated 。 ( productName我可以显示在单元格中没有问题。) 我已经尝试了几种获取date的方法: 这是第一种方法。 我试着用另一个Parse对象来查询它: var productName = [String]() var timeCreated = [NSDate]() //Arrays above the viewDidLoad() to store the productName and the timeCreated override func viewDidLoad() { super.viewDidLoad() var query = PFQuery(className: "ProductInfo") query.findObjectsInBackgroundWithBlock ({ (objects, error) -> Void in if let objects = objects { self.productName.removeAll(keepCapacity: […]

每日UILocalNotification不止一次射击

你好,我面临一个奇怪的问题。 其实我想在上午8:00安排每日通知(每天一次)。 以下是我安排每日通知的代码。 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm"]; NSDate *date = [[NSDate alloc] init]; date = [formatter dateFromString:@"08:00"]; UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = date; localNotification.timeZone=[NSTimeZone defaultTimeZone]; localNotification.alertBody = @"You just received a local notification"; localNotification.alertAction = @"View Details"; localNotification.soundName = UILocalNotificationDefaultSoundName; localNotification.repeatInterval = NSDayCalendarUnit; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; [formatter release]; […]

NSDate早1小时?

我正在使用下面的代码来设置一个date对象: NSDate *date = [NSDate date]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date]; [components setHour: 18]; [components setMinute: 00]; [components setSecond: 00]; reminderDate = [gregorian dateFromComponents: components]; 但是,当我NSLog提醒date我得到以下输出: Time: 2012-08-29 17:00:00 +0000 哪一个是早一个小时 ,任何人都可以解释什么是我需要做的,以便在reminderDate中存储正确的date? 谢谢, Tysin

如何用NSDateFormatterparsing这些时区?

我正在parsing大量互联网date。 首先,我尝试使用en_US_POSIX语言环境的格式化程序,然后使用en_GB 。 代码看起来或多或less像这样: { NSDate *date = [dateString dateWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z (zzz)" localeIdentifier:@"en_US_POSIX"]; if (date) return date; date = [dateString dateWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z (zzz)" localeIdentifier:@"en_GB"]; return date; } – (NSDate*) dateWithDateFormat:(NSString*)dateFormat localeIdentifier:(NSString*)localeIdentifier { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier]; formatter.dateFormat = dateFormat; [formatter […]

无法使用NSDateFormatter从stringparsingdate

我坚持了一段时间在使用NSDateFormatterstringparsingdate string中的date格式如下 1/1/2011 12:00:00 AM 以下是我用来parsing的代码 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; [dateFormatter setDateStyle:NSDateFormatterShortStyle]; NSDate *date = [[NSDate alloc]init]; date = [dateFormatter dateFromString:@"1/1/2011 12:00:00 AM"]; 此代码与date @“2011年12月31日”和格式@“MM / dd / yyyy” 请帮忙