nsdate

How can I use NSDateFormatter to get the string “Yesterday”? [closed]

一曲冷凌霜 提交于 2019-12-23 07:38:18
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I want to format my NSDate so that a date that occurred yesterday will be displayed as "Yesterday'. Can this be done using NSDateFormatter ? 回答1: Use, [dateFormatter setDoesRelativeDateFormatting:YES] to indicate

Escape NSDateFormatter String

懵懂的女人 提交于 2019-12-23 07:15:12
问题 How to escape characters from NSDateFormatter format? NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init]; [dateFormater setDateFormat:@"dd/MM/yyyy \\a\\t HH:mm"]; NSString *dateFormated = [dateFormater stringFromDate:currentDate]; NSLog(@"%@", dateFormated); 回答1: You can escape text by enclosing it in single quotes: [dateFormater setDateFormat:@"dd/MM/yyyy 'at' HH:mm"]; From the docs: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

Escape NSDateFormatter String

二次信任 提交于 2019-12-23 07:14:59
问题 How to escape characters from NSDateFormatter format? NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init]; [dateFormater setDateFormat:@"dd/MM/yyyy \\a\\t HH:mm"]; NSString *dateFormated = [dateFormater stringFromDate:currentDate]; NSLog(@"%@", dateFormated); 回答1: You can escape text by enclosing it in single quotes: [dateFormater setDateFormat:@"dd/MM/yyyy 'at' HH:mm"]; From the docs: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

Problem formatting date using NSDateFormatter

我只是一个虾纸丫 提交于 2019-12-23 07:03:23
问题 I have the following date: 2011-09-09T18:01:47Z I want it to appear as "9/9/11 at 1:47PM" whatever the correct time is This code returns a null string: NSLog(@"TIME: %@",[message valueForKey:@"created_at"]); NSString* time = [message valueForKey:@"created_at"]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"]; NSDate* newTime = [dateFormatter dateFromString:time]; [dateFormatter setDateFormat:@"MM-dd-yy at HH:mm:ss"];

Creating NSDate from components without “timezone correction”

假装没事ソ 提交于 2019-12-23 07:00:30
问题 I have a function func createDate(day: Int, month: Int, year: Int) -> NSDate { var comp = NSDateComponents() comp.day = day comp.month = month comp.year = year var cal = NSCalendar.currentCalendar() if var date = cal.dateFromComponents(comp) { return date } return NSDate() } If I call it with createDate(07, 01, 1984) the output is 1984-01-06 23:00:00 +0000 . I assume that there is some influence from the time zone. How can I adjust my code so that the output will be 1984-01-07 00:00:00 +0000

Converting timestamp string with T and Z characters to NSDate [duplicate]

依然范特西╮ 提交于 2019-12-23 06:35:07
问题 This question already has answers here : Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate? (8 answers) Closed 5 years ago . I don't know how to convert this string to NSDate. Date is in this format "2012-10-21T07:00:00Z" I guess the problem is that I have no clue what those T and Z mean in the string :) NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]; NSDate *dateStart = [formatter dateFromString:@

Converting timestamp string with T and Z characters to NSDate [duplicate]

帅比萌擦擦* 提交于 2019-12-23 06:35:06
问题 This question already has answers here : Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate? (8 answers) Closed 5 years ago . I don't know how to convert this string to NSDate. Date is in this format "2012-10-21T07:00:00Z" I guess the problem is that I have no clue what those T and Z mean in the string :) NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-ddTHH:mm:ssZ"]; NSDate *dateStart = [formatter dateFromString:@

24hr & uiDatePicker

只谈情不闲聊 提交于 2019-12-23 03:04:14
问题 I need the time from my uiDatePicker to be in 24hr format, I understand you can't force this mode if the device is set to display AM/PM? If thats the case, how can I detect the device is in 24hr mode (or not) so I can add 12 to my PM times? Many thanks for any help... 回答1: Wel you can, you need to set the local: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"NL"];

Sorting NSDates

坚强是说给别人听的谎言 提交于 2019-12-23 03:03:06
问题 i have several dictionaries in my program,i have put all those dictionaries in an array i want to sort those dates accordingly dictionary should exchange its position,below shown is the code i am using,but i am not getting it sorted.Please help me to fix this issue **NSLog(@"before sorting---%d",[allDataArray count]); for(int i=0;i<[allDataArray count]-1;i++){ NSString *dateStr1=[[allDataArray objectAtIndex:i]objectForKey:@"Date"]; for(int j=i+1;j<[allDataArray count];j++){ NSString *dateStr2

iOS - UITableView Sections based on date ranges

♀尐吖头ヾ 提交于 2019-12-23 02:36:30
问题 I've got an issue and I'm wondering if it's possible to solve. I have a UITableView that uses Core Data and NSFetchedResultsController. A big part of my app is organizing things based on dates. Ideally, I'd like to divide the TableView into sections based off of 3 date ranges. These ranges would be between now and 2 days, between 2 days and 6 days, and 10 days and beyond. The user has a UIDatePicker, and when they enter a date it would be automatically put into one of these organized sections