I have a date textview. And my textview holds a date string like 2011.09.17. Well I still do want to have that but I also want to add some more user friendly info for some specific dates like today or yesterday. For example if today is 2011.09.17 I want my textview to have value of yesterday instead 2011.09.16 and today instead 2011.09.17.
well I already managed to do this :), but in the ugly way :(. I do this with a lot of 'if->than' which is really uglly and what ever I want to add some new rule like if the date is older than one year I want to put string like last year or so.... I really need to add ugly logic.
My question is is there a nicer way to do this ? is there something like design pattern for this ? What is the recommended way to do this ? I am sure that many people have encounter this kind of problems
if there some bather approach than thousand of ifs ? if not thanks any way at least I will stop searching for bather solution
any suggestions , snippet or so will be appreciated
Thanks
Many people get confused about how to write dates with commas, so here is a rule of thumb: in the month-day-year format (used in the United States), place commas after the day and year. In the day-month-year format (used in the UK and other countries), do not use commas at all. On May 13th, 2007 Daniel was born.
The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD.
The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.
You could try getRelativeDateTimeString
in DateUtils http://developer.android.com/reference/android/text/format/DateUtils.html
I usually use this handy java library for Relative Time formatting. Prety Time Library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With