nsdate

Swift reading date incorrectly

喜夏-厌秋 提交于 2020-01-17 03:42:10
问题 I am working on an app where I need to store and read dates. I am finding that Swift will sometimes get the day wrong. var testDate2 = "2016-10-11 17:00:00 +0000" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss Z" let showDate2 = dateFormatter.date(from: testDate2) let calendar = NSCalendar.current let showDate2Components = calendar.dateComponents([.day, .month, .year], from: showDate2!) print (showDate2!) print (showDate2Components.day!) print (showDate2!)

Unable to parse date from string using NSDateFormatter [closed]

不羁的心 提交于 2020-01-16 18:39:34
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I am stuck for a while parsing date in string using NSDateFormatter Date in string is in below format 1/1/2011 12:00:00 AM Below is the code I use to

How to convert string value into date in iPhone?

ぐ巨炮叔叔 提交于 2020-01-15 11:11:46
问题 I want convert string value into date in my project because I am fetching XML value from web. In XML file I get weather condition and there all value in this weather condition I get current date but my forecastcondition is not come in date it comes in string value, like this: friday saturday and sunday Like this value are come in my forecast condition day this string value come in Day_of_week [Day_of_week] means it shows like this: friday,saturday,sunday How can I convert this string value

NSDateComponents Time Profile

最后都变了- 提交于 2020-01-15 07:40:29
问题 My problem is to do with the Time Profile of NSDateComponents operations given in the code snippet below. I have a method that iterates over a large array of NSDate objects Part of the method requires that I discard the Hour, Minute and seconds of each date. To do this I have 3 steps: I create an NSDateComponents object from my original date. I set the H:M:S elements to 0 I get my new date object that has H:M:S set to 0 as needed The Issue: Steps 1 & 3 above are taking a huge percentage of my

Check if NSDate is in this week or next week

喜欢而已 提交于 2020-01-14 19:20:09
问题 there is a way to check if an NSDate is this week or is next week? i know that today is: [NSDate date] and then how i can do? 回答1: Use NSDateComponents, something like this: NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *today = [NSDate date]; NSDateComponents *todaysComponents = [gregorian components:NSWeekCalendarUnit fromDate:date]; NSUInteger todaysWeek = [todaysComponents week]; NSDate *anotherDate = [NSDate date]; NSDateComponents

Measuring time Interval Since Now

ぃ、小莉子 提交于 2020-01-14 14:32:11
问题 anyone know or can provide some example code relating to "timeIntervalSinceNow" method... I need something like... time2(when app eneters foreground) - time1(when app enters background) = time3(the difference in times)... this is so i can use this number(pref in seconds) to calculate the time i have lost while the app has been in background !! I am having trying trying to create the date objects, receive the object and display/use in a label.... 回答1: timeIntervalSinceNow tells you the offset

Swift UITextField subclass handle text change programmatically

三世轮回 提交于 2020-01-14 07:32:31
问题 I have a subclass of UITextField that is specific to handle Date text. I have a tableviewcell that uses this text field: let dateInput: DateTextField Now the controller needs to initialize the text of the dateInput prior to display as follows: cell.dateInput.text = "01/29/2016" Now, I want to be able to detect that the text changed from the subclass so that I can update the internal date variable so that is it in-sync with the text. I implemented the textfield delegate methods but that just

Swift UITextField subclass handle text change programmatically

自古美人都是妖i 提交于 2020-01-14 07:32:10
问题 I have a subclass of UITextField that is specific to handle Date text. I have a tableviewcell that uses this text field: let dateInput: DateTextField Now the controller needs to initialize the text of the dateInput prior to display as follows: cell.dateInput.text = "01/29/2016" Now, I want to be able to detect that the text changed from the subclass so that I can update the internal date variable so that is it in-sync with the text. I implemented the textfield delegate methods but that just

format NSString to NSDate

妖精的绣舞 提交于 2020-01-14 05:28:24
问题 i take the user date from facebook , it look like "birthday_date" = "03/04/1987" i wrote this code NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"dd/MM/YYYY"]; NSDate *dateFromString = [dateFormatter dateFromString:birthDate]; NSLog(@"dateformstring %@ ",dateFromString); [birthPicker setDate:dateFromString animated:YES]; and the result date from string si : 1988-12-25 23:00:00 +0000 , i have this date selected in the picker , I do

Determine NSDate for Memorial Day in a given year

柔情痞子 提交于 2020-01-13 20:16:47
问题 Is there a better way to determine the NSDate for Memorial Day (the last Monday in May) in a given year? NSInteger aGivenYear = 2013 ; NSCalendar* calendar = [NSCalendar currentCalendar] ; NSDateComponents* firstMondayInJuneComponents = [NSDateComponents new] ; firstMondayInJuneComponents.month = 6 ; // Thanks, Martin R., for pointing out that `weekOfMonth` is wrong for returning the first Monday in June. firstMondayInJuneComponents.weekOfMonth = 1 ; firstMondayInJuneComponents.weekday = 2 ;