nsdateformatter

converting string to NSDate issue: [__NSDate Length] unrecognized selected

徘徊边缘 提交于 2019-12-05 01:05:42
indexNumber.row is a date like 2012-03-09 23:00:00 +0000 . I've tried a handful of different ways to get my date into an NSDate , but I keep getting the title error. NSString *inputString = [self.measurements objectAtIndex:indexNumber.row]; // Convert string to date object NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *date = [dateFormatter dateFromString:inputString ]; NSLog(@"date format is: %@", date); Any ideas why I get the following error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:

Using NSDateFormatter on the iPhone, protect locale but lose date components

拥有回忆 提交于 2019-12-05 00:25:55
This is a slightly tricky question. I am using NSDateFormatter on the iPhone but I wanted to only show a standard date without the years component. But retain the users locale formatting for their date. I could easily override the formatting using [dateFormatter setDateFormat:@"h:mma EEEE MMMM d"]; // hurl.ws/43p9 (date formatting) But now the date is in my in en-nz format eg 12:01PM Wednesday July 7. So I have totally killed the locale for any other users around the world. I would like to say. Give me the correct localized date for this users region but omit the years component. Since the

change NSDate from one time zone to another [closed]

青春壹個敷衍的年華 提交于 2019-12-04 23:20:07
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Given a date in NSString like "2012-12-17 04:36:25" (which is GMT) how one can simply change it to other time zones like EST, CST All the steps I saw so far took so many unnecessary steps Inder Kumar Rathore NSString *str = @"2012-12-17

find total number of days between two dates in iphone

雨燕双飞 提交于 2019-12-04 20:41:20
问题 I would like to find total number of days between two dates. e.g. today is 01-01-2011(DD-MM-YYYY) and second date is (25-03-2011), how would I find the total number of days? NSDate *currentdate=[NSDate date]; NSLog(@"curretdate is ==%@",currentdate); NSDateFormatter *tempFormatter1 = [[[NSDateFormatter alloc]init]autorelease]; [tempFormatter1 setDateFormat:@"dd-mm-YYYY hh:mm:ss"]; NSDate *toDate = [tempFormatter1 dateFromString:@"20-04-2011 09:00:00"]; NSLog(@"toDate ==%@",toDate); 回答1: In

How to get Date from String in swift 3?

半城伤御伤魂 提交于 2019-12-04 18:39:17
I have save the timestamp in data base like: "NSDate()" // which save Date like this: 2017-03-10 22:53:30 +0000 Now i need to get Date from this string, I have tried every format but it's keep returning nil. let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss ZZZ" dateFormatter.locale = Locale(identifier: "en_US") print(dateFormatter.date(from: "2017-03-10 22:53:30 +0000") ?? "No Value") // always return No Value here i have tried so many formats e.g: yyyy-MM-dd hh:mm:ss +zzzz yyyy-MM-dd hh:mm:ss xx Have seen many answers but no answer is working on this format

How to convert date format from dd/MM/YYYY to YYYY-MM-dd in swift [duplicate]

我的未来我决定 提交于 2019-12-04 18:21:54
问题 This question already has answers here : Format a date from a string (4 answers) Closed 3 years ago . I tired to covert from 21/07/2016 to 2 016-07-21 but got this date 2015-12-20 Here is the Code that i have try let inputFormatter = NSDateFormatter() inputFormatter.dateFormat = "MM/dd/YYYY" let outputFormatter = NSDateFormatter() outputFormatter.dateFormat = "YYYY-MM-dd" let showDate = inputFormatter.dateFromString("07/21/2016") let resultString = outputFormatter.stringFromDate(showDate!)

Date is getting changed while converting to NSDate from NSString

你说的曾经没有我的故事 提交于 2019-12-04 17:02:50
I am converting NSString to NSDate with help of NSDateFormatter. Now code works fine here in all OS with device & simulator but it is creating different Output at UK, USA region. Here is the code that I am using. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *dateString=[NSString stringWithString:@"2010-09-05 04:00:00"]; NSDate *dateObj = [dateFormatter dateFromString:dateString]; Actual date is : 2010-09-05 04:00:00 Output at USA : 2010-09-04 21:00:00 -0700 It seems the problem is at TimeZone/Locale somewhere

Swift iOS doesRelativeDateFormatting have different values besides “Today” and “Yesterday”?

强颜欢笑 提交于 2019-12-04 16:33:56
问题 I have a number of dates that I am trying to represent using a relative date such as "Today, Yesterday, 1 week ago, 1 month ago" etc... This is the Swift code I am using: let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = .MediumStyle dateFormatter.doesRelativeDateFormatting = true let uploadDate = dateFormatter.stringFromDate(date) Only "Today" and "Yesterday" are represented and the rest of the dates appear like the below: Nov 24, 2014 Nov 17, 2014 etc... Is there another way

how to use NSDateFormatter to see “Today” string

那年仲夏 提交于 2019-12-04 15:45:58
问题 apple use it in the messages app for today messages Today 11:45 AM Yesterday 11:45 AM i see it in the apple developer site To specify a custom fixed format for a date formatter, you use setDateFormat:. The format string uses the format patterns from the Unicode Technical Standard #35. The version of the standard varies with release of the operating system: Calendar Fields fields ( alias | (field*, special*)) > field ( alias | (displayName?, relative*, special*)) > Translations may be supplied

Producing an NSDate with NSDateFormatter Yielding nil NSDate Value

余生颓废 提交于 2019-12-04 15:42:39
I am trying to produce a date from a string with the following: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MMMM dd, yyyy HH:mm:ss"]; NSLog(@"ENDINGDATE: %@", [closure objectForKey:@"ENDINGDATE"]); NSDate *tempDate = [dateFormatter dateFromString:[closure objectForKey:@"ENDINGDATE"]]; The ENDINGDATE NSLog produces the following: ENDINGDATE: April, 21 2011 20:00:00 Everything seems to be fine, so I am stumped as to why tempDate is being set to nil. Any ideas? Thanks! The , is misplaced. It should be after MMMM . So the format should have