Relative date formatting, output for past dates?

I am considering using -[NSDateFormatter setDoesRelativeDateFormatting:] to represent dates as "Today" or "Yesterday." I only look at dates in the past, but I'm curious what options I see localized for the UK.

Simply

  • "Today"
  • "Yesterday"

or something more confusing, for example

  • "Day before yesterday"

Are the outputs listed anywhere possible so that I can get an idea of ​​the screen space needed to display them correctly?

+6
source share
1 answer

Yes. They appear in the console window when you run the following program:

 #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterFullStyle]; [formatter setDoesRelativeDateFormatting:YES]; NSCalendar * cal = [[NSLocale currentLocale] objectForKey:NSLocaleCalendar]; NSDateComponents * minusOneDay = [[NSDateComponents alloc] init]; [minusOneDay setDay:-1]; NSDate * today = [NSDate date]; NSDate * date = [NSDate date]; while( 1 > [[cal components:NSYearCalendarUnit fromDate:date toDate:today options:0] year] ){ NSLog(@"%@", [formatter stringFromDate:date]); date = [cal dateByAddingComponents:minusOneDay toDate:date options:0]; } } return 0; } 

In my area, the list seems to be just Tomorrow, Today, and Yesterday.

+8
source

Source: https://habr.com/ru/post/895427/


All Articles