nsdate

Core Data sort tableview by formatted date

我与影子孤独终老i 提交于 2019-12-08 06:08:48
问题 I know how to sort Core Data objects in a tableview by NsDate, but this by default seems to create a new section for each object. I want to sort them by a medium formatted date with NSDateFormatter. How would I do this? For example, if I have 3 objects created on the same day, I want them to be in the same section with the section title being that Day, no time needed. Each object has an NSDate property. Thanks for your help. This is the code I have in fetchedResultsController with rgeorge's

NSDate is converting really strangely

不羁岁月 提交于 2019-12-08 06:07:24
问题 I have a time: 7:46 am I want to convert this to NSDate. I do this: NSDateFormatter *f = [NSDateFormatter new]; [f setDateFormat:@"h:mm a"]; NSDate *sr = [f dateFromString:@"7:46 am"]; I NSLog sr and I get 1969-12-31 22:46:00 +0000 Those times are not the same. Why is this so messed up? 回答1: No. Its not strange. NSDateConverter & NSDate are just doing their intended job here. You are trying to convert "7:46 am" into a date. It contains only the time. No date is specified in the string. NSDate

Get name of days between two date in ios?

陌路散爱 提交于 2019-12-08 05:44:19
问题 How to get name of days between two dates in ios? Example: Input: Start Date: 3-11-2012 End date: 5-11-2012 Output: 3-11-2012 Wednesday 4-11-2012 Thursday 5-11-2012 Friday Thanks.. 回答1: try this, NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd"]; NSDate *startDate = [df dateFromString:@"2012-07-20"]; // your start date NSDate *endDate = [NSDate date]; // your end date NSDateComponents *dayDifference = [[NSDateComponents alloc] init]; NSMutableArray *dates

Validation for input string is Date or not?

自闭症网瘾萝莉.ら 提交于 2019-12-08 05:16:28
问题 I have a textfield where the user can enter their date of birth, now i wants to make sure whether the input is of date format before saving into database. I gone through the SO , but still i didn't get the answer. Can anyone tell me how to validate(is it date) the input. The date format would be MM/DD/YYYY Note:I don't want the user to select date through date picker. 回答1: Try this NSString *dateFromTextfield = @"07/24/2013"; // Convert string to date object NSDateFormatter *dateFormat = [

NSDate countdown from NOW to NSDate

爱⌒轻易说出口 提交于 2019-12-08 04:50:33
问题 How can I show a countdown in HH:mm:ss format from NOW to a desired NSDate that will happen in the future? 回答1: You have to use a timer for ticking the date. Store a future date, and keep on substracting future date - [nsdate today]... Calculate the time in seconds and calculate it into Hours, minutes, seconds... //Make two properties NSDate *nowDate, *futureDate futureDate=...; nowDate=[NSDate date]; long elapsedSeconds=[nowDate timeIntervalSinceDate:futureDate]; NSLog(@"Elaped seconds:%ld

Check date format in Objective-C

北慕城南 提交于 2019-12-08 03:20:45
问题 I'm receiving a string containing a date. I want to check if it has the format "dd/MM/yyyy". Right now I'm using code that I found in this same page: NSDate *date = [dateFormatter dateFromString:dateString]; if(date == nil) { correctFormat = false; } It works for some cases, but for example, if I input "22-12-1996" instead of "22/12/1996", it creates the date anyway. Is there another way that's consistent? 回答1: NSDateFormatter handle format of string dates. Instances of NSDateFormatter create

Converting Adobe PDF date String to NSDate

无人久伴 提交于 2019-12-08 03:16:51
问题 The input string is '20100908041312' the format is year,month,day,Hours,minutes,seconds,time zone and I have ben trying to convert it to an NSDate with this: @"yyyyMMddHHmmsszz" But NSDate is nil, anyone see what I'm doing wrong? -(NSDate*)convertPDFDateStringAsDate:(NSString*) _string{ //20100908041312 //year month day Hours minutes seconds and time zone NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyyMMddHHmmsszz"]; NSDate *date = [dateFormat

How to get the hours,minute and am/pm from a date? [duplicate]

给你一囗甜甜゛ 提交于 2019-12-08 01:48:09
问题 This question already has answers here : How to get the time in am/pm format iphone NSDateFormatter? (7 answers) Convert NSString to NSDate with new format (2 answers) Closed 6 years ago . I tried to extract hours,minute and am/pm from date but i am getting NULL output. I have shown below my code, please review it. NSString *dateStr=@"29/07/2013 02:00am"; NSDateFormatter * formatter=[[NSDateFormatter alloc] init]; [formatter setDateFormat:@"hh:mmaa"]; NSDate *date=[formatter dateFromString

How to convert string date into NSDate with NSDateFormatter

喜欢而已 提交于 2019-12-08 01:04:31
问题 I have the following date as NSString: Thu May 29 14:22:40 UTC 2014 I've tried to convert it to NSDate with the following code: NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = @"EEE MMM d HH:mm:ss zzz yyyy"; NSDate *utc = [fmt dateFromString:@"Thu May 29 14:22:40 UTC 2014"]; NSLog(@"UTC Date:%@:", utc); The result is nil I've tried several dateFormat regex expressions but with no luck. What am I missing here? 回答1: Use NSDataDetector class a subclasss of

Automatic select a date in datepicker in swift langauge

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 00:36:57
问题 I have a date "Thursday, 18 Sep 2014" in this format. when i click a "change date" button. how we can automatic select a this date in datepicker in swift language. 回答1: var dateString = "Thursday, 18 Sep 2014" var df = NSDateFormatter() df.dateFormat = "eeee, dd MM yyyy" var date = df.dateFromString(dateString) if let unwrappedDate = date { datePicker.setDate(unwrappedDate, animated: false) } 来源: https://stackoverflow.com/questions/25859432/automatic-select-a-date-in-datepicker-in-swift