Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way with NSDateFormatter to get "Today", "Tomorrow","Friday" style dates?

I'm working on setting up NSDateFormatter to explain the date, and I'd like something short but more intuitive than 15/07/10. I think I've seen some formats that will say simply "Today" or "Tomorrow" or the day of the week for subsequent days of the same week. Is there a simple apple-approved way to get this type of date?

Thanks.

like image 838
Alex Gosselin Avatar asked Jul 15 '10 02:07

Alex Gosselin


2 Answers

If you're targeting iOS 4 or later, you can call [yourFormatter setDoesRelativeDateFormatting:YES]. Otherwise, you'll most likely need a custom subclass. As for days of the week, what jer said.

like image 134
Wevah Avatar answered Nov 09 '22 01:11

Wevah


Ensure you set up your locale with the NSDateFormatter appropriately, and then ask for the weekdaySymbols. This will return an array with the days of the week in the locale you specify.

like image 23
jer Avatar answered Nov 09 '22 01:11

jer