Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show relative date or time, not both on iOS?

I'm currently doing this:

NSDateFormater *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterMediumStyle];
[dateFormat setTimeStyle:NSDateFormatterShortStyle];
[dateFormat setDoesRelativeDateFormatting:YES];

...

label.text = [dateFormat stringFromDate:thedate];

And this is producing:

Today, 1:00 PM
Yesterday, 1:00 PM
Oct 5, 2012, 1:00 PM
Oct 5, 2013, 1:00 PM

What I want is this:

1:00 PM
Yesterday
Oct 5
Oct 5 2013

Showing current year is OK (3rd line). At the very least the time should show only if it's today. On the iPhone the recent calls list does this. I need to do this because I have very little space for the date.

(Something like isEqualToString@"Today" will not work - This only works for English)

What's the easiest way to do this?

like image 573
Luke Avatar asked Dec 05 '25 16:12

Luke


1 Answers

You'll have to write your own formatters to deal with this.

Have a look at https://github.com/mattt/FormatterKit to see how you could go about it.

like image 137
Abizern Avatar answered Dec 07 '25 07:12

Abizern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!