nsdate

NSFetchedResultsController titleForHeaderInSection with formatted NSDate

↘锁芯ラ 提交于 2019-12-03 08:21:26
In my Core Data app I am using a FetchedResultsController. Usually to set titles for headers in a UITableView you would implement the following method like so: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [[<#Fetched results controller#> sections] objectAtIndex:section]; return [sectionInfo name]; } where [sectionInfo name] returns a NSString. my sectionKeyPath is based on an NSDate and this all works fine apart from the section headers it gives me are the raw date description strings (e.g. 12/12

How to turn a NSString into NSDate?

时光怂恿深爱的人放手 提交于 2019-12-03 08:21:20
Ive been racking my brains with no luck. Could someone please tell me how i would convert this string: "2011-01-13T17:00:00+11:00" into a NSDate? The unicode date format doc is here Also, for your situation, you could try this: // original string NSString *str = [NSString stringWithFormat:@"2011-01-13T17:00:00+11:00"]; // convert to date NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; // ignore +11 and use timezone name instead of seconds from gmt [dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss'+11:00'"]; [dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Australia

How to check if two NSDates are from the same day [duplicate]

拥有回忆 提交于 2019-12-03 08:06:21
问题 This question already has answers here : Comparing NSDates without time component (16 answers) Closed 3 years ago . I am working on ios development and I find it really hard to check if two NSDates are from the same day. I tried to use this fetchDateList() // Check date let date = NSDate() // setup date formatter let dateFormatter = NSDateFormatter() // set current time zone dateFormatter.locale = NSLocale.currentLocale() let latestDate = dataList[dataList.count-1].valueForKey("representDate"

Check whether a specified date is today, yesterday, or a future date

匆匆过客 提交于 2019-12-03 06:17:59
I have one query regarding NSDate. I have a date i.e. "2011-10-04 07:36:38 +0000", and I want to check if this date is yesterday, or today or a future date. How would I go about this? Shri Try this: Note: Change the date format as per your need. NSDateFormatter* df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"MM/dd/yyyy"]; NSDate* enteredDate = [df dateFromString:@"10/04/2011"]; NSDate * today = [NSDate date]; NSComparisonResult result = [today compare:enteredDate]; switch (result) { case NSOrderedAscending: NSLog(@"Future Date"); break; case NSOrderedDescending: NSLog(@"Earlier Date"

Comparing an NSDate to [NSDate date]

元气小坏坏 提交于 2019-12-03 06:02:41
I am trying to force a user to select a date in the future with a date picker. I obviously used the compare: method, however, when I do the following code, even if it's the same date as [NSDate date], it tells the executes the if statement. Here is my code: if ([datePicker.date compare:[NSDate date]] == NSOrderedAscending) // If the picked date is earlier than today { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hmm, this date is earlier than today" message:@"The date you've selected is earlier than today's date, please pick another" delegate:nil cancelButtonTitle:@"Okay, I'll

Working with NSDate components in Swift

我们两清 提交于 2019-12-03 05:58:31
I have a date that I need to split in some components. for example let components = NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitHour let date = calendar.components(components, fromDate: aDate, toDate: NSDate(), options: nil) var dateToPrint = "\(date.day) days \(date.hour) hours" dateToPrint will be the number of days and hours from aDate to now. But if i want the number of weeks instead of days let components = NSCalendarUnit.CalendarUnitWeek | NSCalendarUnit.CalendarUnitHour let date = calendar.components(components, fromDate: aDate, toDate: NSDate(), options: nil) var

NSDate return “1604” for year value?

若如初见. 提交于 2019-12-03 05:55:51
I'm try to get birth data for contacts but if user does not choose year or the contact come from Facebook and the year or the data it self is hidden so it give me the "1604" value for the year u can see what i mean in the image. Congratulations, you've discovered an implementation detail! First off, Contacts stores dates as points in time, and it is impossible to store a point in time without a year, because every point in time has a year. Thus, a decision had to be made about how Address Book would store an "unknown" year in a date. It was decided that "1604" would be a fine year, for several

iphone how can i get month name from month number? [duplicate]

耗尽温柔 提交于 2019-12-03 05:54:04
This question already has answers here : iOS: How to get a proper Month name from a number? (11 answers) Possible Duplicate: iOS: How to get a proper Month name from a number? How can I get month name from month number? I have month number like 02 , but would like the month as a string, in this case February . Something like this: int monthNumber = 11; NSString * dateString = [NSString stringWithFormat: @"%d", monthNumber]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM"]; NSDate* myDate = [dateFormatter dateFromString:dateString];

Swift convert time to time ago

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 05:53:01
问题 In Swift5, we have RelativeDateTimeFormatter Prior to Swift5: I'm trying to convert time to time ago, what i wanna do is: from 1 to 15 seconds it will say " Just now " from 60 minutes to 119 minutes it will say " an hour ago " from 24 hours to 47 hours it will say " Yesterday " from 7 days to 7 days and 23 hours it will say " a week ago " I'm not sure about my counting if am i wrong feel free to fix it for me Here is the code extension NSDate { struct Date { static let timeFormatter:

NSDateFormatter “Month” in 3 letters instead of full word

你说的曾经没有我的故事 提交于 2019-12-03 05:36:29
问题 NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd-MM-YYYY HH:mm"]; [formatter setTimeZone:[NSTimeZone systemTimeZone]]; If i choose MM i get the month in number: 09-05-2012 15:33 If i choose MMMM i get the month in word: 09-May-2012 15:33 What i wanted, was the month in 3 letters abbreviation. Eg: January would be Jan In this case May is correct because it only has 3 letters. 回答1: Have you tried: [formatter setDateFormat:@"dd-MMM-YYYY HH:mm"]; and then