nsdate

NSTimer not firing when runloop is blocked

旧城冷巷雨未停 提交于 2019-11-27 11:56:27
I am just about finished with my app and beta testing found a bug in the stopwatch portion... The stopwatch uses an nstimer to do the counting and has a table for storing laps, but when the lap table is scrolled the watch stops or pauses and does not make up for the lost time. This was stalling was eliminated by using: startingTime = [[NSDate date] timeIntervalSince1970]; to calculate the elapsed time. but I am still using the NSTimer to trigger every 0.1 secs and that means that the scrolling still stalls the timer even though the elapsed time will be updated correctly in the end... and

iOS: Compare two NSDate-s without time portion

爷,独闯天下 提交于 2019-11-27 11:56:01
I want to compare two dates: date1 and date2 2011-06-06 12:59:48.994 Project[419:707] firstDate:2011-06-06 10:59:21 +0000 2011-06-06 12:59:49.004 Project[419:707] selectedData:2011-06-06 10:59:17 +0000 but these dates have different time and when I use NSOrderedSame it don't work fine, how can I solve? my code: NSDate *firstDate = [[appDelegate.project objectAtIndex:i]objectAtIndex:3]; NSDate *secondDate = [[appDelegate.project objectAtIndex:i]objectAtIndex:4]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSInteger comps = (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit);

Truncate NSDate (Zero-out time)

China☆狼群 提交于 2019-11-27 11:55:39
I want to generate a new NSDate with 0 hours , 0 minutes , and 0 seconds for time. The source date can be any random NSDate . Is there a way to achieve this? The documentation did not help me with this. Example Have: 2010-10-30 10:14:13 GMT Want: 2010-10-30 00:00:00 GMT Evan Mulawski unsigned int flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* components = [calendar components:flags fromDate:date]; NSDate* dateOnly = [calendar dateFromComponents:components]; date is the date you want to remove the time

UIDatePicker, setting maximum and minimum dates based on todays date

為{幸葍}努か 提交于 2019-11-27 11:54:10
If I have a UIDatePicker, and I wish to set the minimum and maximum date range to be between thirty years ago and thirty years in the future, how would I set that up? Not tested, but you probably want something like this. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *currentDate = [NSDate date]; NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setYear:30]; NSDate *maxDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0]; [comps setYear:-30]; NSDate *minDate = [calendar dateByAddingComponents:comps

Date/Time parsing in iOS: how to deal (or not deal) with timezones?

喜欢而已 提交于 2019-11-27 11:54:08
问题 I have an ASP.NET MVC 3 website that communicates with my iOS app via JSON. As part of the objects sent in the JSON response, I have dates in the format of yyyy-MM-dd HH:mm:ss ZZZ which outputs 2011-04-05 16:28:22 -07:00 . How do I parse that in iOS? This is the code I'm messing around with right now: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"]; [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; NSDate *date =

GMT timezone conversion in objective c

倾然丶 夕夏残阳落幕 提交于 2019-11-27 11:51:37
I am trying to convert nsstring to nsdate and then to the systemtimezone. Is my code right? Any help appreciated. NSString *str=@"2012-01-15 06:27:42"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *dateFromString = [dateFormatter dateFromString:str]; NSDate* sourceDate = dateFromString; NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT-07:00"]; NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; NSInteger

Converting UTC date format to local nsdate

旧城冷巷雨未停 提交于 2019-11-27 11:39:29
I am getting from my server a string date in UTC time zone and I need to convert it to the local time zone. MY CODE: let utcTime = "2015-04-01T11:42:00.269Z" let dateFormatter = NSDateFormatter() dateFormatter.timeZone = NSTimeZone(name: "UTC") dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" let date = dateFormatter.dateFromString(utcTime) println("utc: \(utcTime), date: \(date)") this prints - utc: 2015-04-01T11:42:00.269Z, date: Optional(2015-04-01 11:42:00 +0000) if I remove dateFormatter.timeZone = NSTimeZone(name: "UTC") it prints utc: 2015-04-01T11:42:00.269Z, date: Optional

Core Data Save Error (NSValidationErrorKey, Cocoa error 1570) saving NSDate

自作多情 提交于 2019-11-27 11:26:43
问题 I'm getting an error with saving to a Core data object in Xcode. Xcode says that the error is in the NSDate variable 'datum' but I have tried almost everything. Error is: 2011-07-12 18:01:29.068 WeekLijstje[3205:207] Core Data Save Error NSValidationErrorKey datum NSValidationErrorPredicate (null) NSValidationErrorObject <DagLijst: 0x6e2fcd0> (entity: DagLijst; id: 0x6e2fd30 <x-coredata:///DagLijst/t99F423FC-AAE9-4692-9264-EF0FF7A020572> ; data: { Voedsel = nil; datum = nil; hoeveelheid = 0;

Formatting date and time with iPhone SDK?

十年热恋 提交于 2019-11-27 11:03:59
How do I format date and time using iPhone SDK? For example, how would I extract the date from 9/4/2024 12:00:00 AM to NSDate? Yit Ming you can format your string using dd/MM/yyyy hh:mm:ss a example as below: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"]; NSLog(@"%@", [dateFormatter dateFromString:@"12/12/2012 12:12:12 AM"]); some more option Now you want all the string formats that can be used with NSDateFormatter. Here is that a: AM/PM A: 0~86399999 (Millisecond of Day) c/cc: 1~7 (Day of Week) ccc: Sun/Mon/Tue/Wed/Thu

How do I get hour and minutes from NSDate?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 10:20:53
In my application I need to get the hour and minute separately: NSString *currentHour=[string1 substringWithRange: NSMakeRange(0,2)]; int currentHourInNumber=[currentHour intValue]; Consider string1 contains 11:59:13 AM which is coming from datepicker. Here if I use above code, it's okay to get hour if it's greater than 9. Else I need to change NSMakeRange(0,1) to get hour between 1 to 9. Are there any methods to get the hour, minutes, etc? Thanks in advance, please provide me sample code. Thomas Müller Use an NSDateFormatter to convert string1 into an NSDate , then get the required