nsdate

Finding time between dates in Swift [duplicate]

痴心易碎 提交于 2019-12-24 13:41:24
问题 This question already has answers here : Getting the difference between two NSDates in (months/days/hours/minutes/seconds) (18 answers) Closed 4 years ago . Hi Im trying to work out the time between two dates using UIpickers and I am lost. I cannot fathom where to go to on this to get the value to plug into the label. Im not sure if I should use components or before the comparison or just after to put it in the label. Thanks for any pointers. let calendar = NSCalendar.currentCalendar() let

Using NSDate to get date for Easter

点点圈 提交于 2019-12-24 13:18:06
问题 I'm working on an application that requires the use of getting dates for national holidays. Below, I was able to get Memorial Day: // Set the components for Memorial Day (last Monday of May) let memorialDayComps = NSDateComponents() memorialDayComps.weekday = 2 memorialDayComps.month = 5 memorialDayComps.year = currentYear var mondaysOfMay = [NSDate]() for var i = 1; i <= 5; i++ { memorialDayComps.weekdayOrdinal = i let monday = calendar.dateFromComponents(memorialDayComps) let components =

Nesting NSDictionary based on value

一世执手 提交于 2019-12-24 11:50:10
问题 i've data from Library that return this: NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:distanceNumber,@"distance",idChallengerN,@"idChallenger",dateFrom, @"date", nil]; [_array addObject:dict]; If i print _array this is there result: { date = "2015-07-31 14:50:40 +0000"; distance = "-1"; idChallenger = 43; }, { date = "2015-07-31 16:18:57 +0000"; distance = "-1"; idChallenger = "-1"; }, { date = "2015-07-31 16:19:05 +0000"; distance = "-1"; idChallenger = "-1"; }, and it's

Incorrect time string with NSDateFormatter with Daylight Saving Time

久未见 提交于 2019-12-24 11:37:23
问题 I'm using CET as my default timezone in my application. In Germany Daylight saving time will start from 29 March 2015 . Now I'm doing some testing to see if my dates will be converted correctly in the future. I used following code to test it. NSTimeZone *timeZone = [NSTimeZone timeZoneWithAbbreviation:@"CET"]; [NSTimeZone setDefaultTimeZone:timeZone]; NSDate *now = [NSDate date]; // 10 Feb, 2015 NSDate *dateAfter29March = [now dateByAddingMonths:2]; // 10 April, 2015 NSDateFormatter

How to disable a button even when it is not running in the background in swift?

為{幸葍}努か 提交于 2019-12-24 11:11:39
问题 When I say not running in the background, I mean when the user double clicked their home button and swipes up, the button will reenable This is the code in my viewDidLoad if let waitingDate:Date = UserDefaults.standard.value(forKey: "waitingDate") as? Date { let currentDate = Date() if(currentDate.compare(waitingDate) == ComparisonResult.orderedDescending) { getPointsOutlet.isEnabled = true } } This is the code in the @IBAction func getPointsOutlet.isEnabled = false let newDate = Calendar

Issue with Core Data attribute returning 0 [duplicate]

痞子三分冷 提交于 2019-12-24 10:18:53
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Core Data not saving NSString. Hey all! Currently experiencing a weird issue with Core Data in my latest application. Basically what I'm accomplishing is that of parsing JSON and adding each object into Core Data under the respective attribute. This works fine as far as I can see from the NSLogs I have set in place. However, when it comes to displaying one of the values in a UITableView, it always returns 0 for

Cocoa - Calculate working days between two dates

爷,独闯天下 提交于 2019-12-24 08:37:09
问题 I new in cocoa programing and I want to know how I get the number of working days between to dates. So only from Monday to Friday. Thanks. 回答1: NSDate *startDate = ...; NSDate *stopDate = ...; NSDateFormatter *df = [NSDateFormatter new]; df.dateFormat = @"yyyy-MM-dd"; startDate = [df dateFromString:[df stringFromDate:startDate]]; // get start of the day NSDateComponents *comps = [NSDateComponents new]; comps.day = 1; // one day in NSDateComponents NSUInteger count = 0; while ([stopDate

Crash when converting string to date

﹥>﹥吖頭↗ 提交于 2019-12-24 07:43:33
问题 In my app I DO NOT want to use the local time on the phone. I want to get the current time in GMT. To do this I have a date formatter with time zone set to GMT. I then do the following to get back the current time: NSString *dateOne = [df stringFromDate:[NSDate date]]; NSDate *date1 = [df dateFromString:dateOne]; My app gets an EXC_BAD_ACCESS though on the dateFromString call. I checked the returned value from dateOne and it's format matches the dateformatters. What am I doing wrong? Is there

how to compare dates in iphone sdk?

时光怂恿深爱的人放手 提交于 2019-12-24 07:05:35
问题 i have two dates i want to compare which one is greater date how do i do this in objective-c? 回答1: From NSDate class reference: NSDate -compare: Returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date. (NSComparisonResult)compare:(NSDate *)anotherDate Parameters anotherDate The date with which to compare the receiver. This value must not be nil. If the value is nil, the behavior is undefined and may change in future versions of Mac OS X.

how to compare dates in iphone sdk?

人走茶凉 提交于 2019-12-24 07:05:15
问题 i have two dates i want to compare which one is greater date how do i do this in objective-c? 回答1: From NSDate class reference: NSDate -compare: Returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date. (NSComparisonResult)compare:(NSDate *)anotherDate Parameters anotherDate The date with which to compare the receiver. This value must not be nil. If the value is nil, the behavior is undefined and may change in future versions of Mac OS X.