nsdateformatter

How to convert date string into format “17 Nov 2010”

▼魔方 西西 提交于 2019-12-09 02:15:36
I have the date that is in format 2010-11-17 .This is of the form NSString . I want to convert this NSString date into format 17 Nov 2010 and display in a label This date is just not the current date but may even be the older dates. So I cant use the [NSDate date] instance to get the date. I tried using NSDateFormatter with the method dateFromString . But it gives me a null value. Here is the code snippet NSString *dates = @”2010-11-16”; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd MMM yyyy"]; NSDate *dates1 = [dateFormatter dateFromString

NSDateFormatter time not changing according to phones settings

霸气de小男生 提交于 2019-12-08 20:20:31
this one is killing me, I have the following date formatter: + (NSDateFormatter *)dateFormatter { static NSDateFormatter *_dateFormatter = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSString *format = [NSDateFormatter dateFormatFromTemplate:@"hh:mm a" options:0 locale:[NSLocale currentLocale]]; _dateFormatter = [[NSDateFormatter alloc] init]; [_dateFormatter setDateFormat:format]; }); return _dateFormatter; } I want the final hour format to be according to the user clock settings, so if the user uses "24-Hour Time", the result should be for example: 19:41 Otherwise the

Why I can't convert string to date in Swift? [duplicate]

南笙酒味 提交于 2019-12-08 13:57:52
问题 This question already has an answer here : dateFromString returns nil for some values (1 answer) Closed 2 years ago . I have this simple code: let string = "2017-02-23 15:26:00"; let df = DateFormatter(); df.dateFormat = "yyyy-MM-dd hh:mm:ss"; let result = df.date(from: string); The result is nil. Why? 回答1: Your date is 24 hour format So it should be HH not hh , so change your date formate to yyyy-MM-dd HH:mm:ss . let string = "2017-02-23 15:26:00" let df = DateFormatter() df.dateFormat =

to display weather forecast for currentday,next day and day after next day in iphone [closed]

[亡魂溺海] 提交于 2019-12-08 13:43:11
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Hi i want to create a weather application.My weather application is such that when user clicks on weather tab weather details of the current location should be displayed in table view.For the same current location,weather details for the current day ,next day and day after next

Get the user's date format? (DMY, MDY, YMD)

為{幸葍}努か 提交于 2019-12-08 13:37:10
问题 I'm creating a form where the user can enter their birthday with 3 UITextFields: 1 for month, 1 for day and 1 for year. I'd like to arrange them based on the user's date format. i.e.: [ MONTH ] [ DAY ] [ YEAR ] for American users, [ DAY ] [ MONTH ] [ YEAR ] for European users, etc. Map of the date format by country: http://en.wikipedia.org/wiki/Date_format_by_country#Map What's the easiest way to get that format? Right now I'm setting the date October, 20 2000 and parsing the string.

ios4 - splitting a date and time from a string into two separate strings

蓝咒 提交于 2019-12-08 12:11:39
问题 I have a JSON feed coming into my app, one of the fields is a combined date & time string which I need to split into discrete date and time strings for display in a table cell. An example of input from the JSON is: 2012-01-18 14:18:00. I'm getting a bit confused with the date formatter, and clearly I'm not doing it right - I've tried a number of tutorials but most just seem to show how to format a date. I've tried something a little like this to get just the time: NSDictionary *rowData =

NSDateFormatter time not changing according to phones settings

狂风中的少年 提交于 2019-12-08 08:24:46
问题 this one is killing me, I have the following date formatter: + (NSDateFormatter *)dateFormatter { static NSDateFormatter *_dateFormatter = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSString *format = [NSDateFormatter dateFormatFromTemplate:@"hh:mm a" options:0 locale:[NSLocale currentLocale]]; _dateFormatter = [[NSDateFormatter alloc] init]; [_dateFormatter setDateFormat:format]; }); return _dateFormatter; } I want the final hour format to be according to the user

Swift displaying the time or date based on timestamp

喜欢而已 提交于 2019-12-08 07:58:17
问题 I have an API that returns data including a timestamp for that record. In swift I have the timestamp element loaded and converted into a double and can then convert that into time. I want to be able to return the time if the date of the record is today and return the date if the record is not today. See below: let unixTimeString:Double = Double(rowData["Timestamp"] as! String)! let date = NSDate(timeIntervalSince1970: unixTimeString) // This is on EST time and has not yet been localised. var

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