正确的方式来格式化日期与像今天,昨天,明天等字符串字符串、正确、昨天、明天

由网友(我的爱已过期)分享简介:我有个约会的TextView。而我的TextView持有日期字符串像2011年9月17号。好吧,我还是希望有这一点,但我也想补充像今天或昨天的一些具体日期一些更加人性化的信息。例如,如果今天是2011年9月17日我希望我的TextView有昨天今天的价值,而不是2011.09.1​​6,而是2011年9月17日。I...

我有个约会的TextView。而我的TextView持有日期字符串像2011年9月17号。好吧,我还是希望有这一点,但我也想补充像今天或昨天的一些具体日期一些更加人性化的信息。例如,如果今天是2011年9月17日我希望我的TextView有昨天今天的价值,而不是2011.09.1​​6,而是2011年9月17日。

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.

好,我已经成功地做​​到这一点:),但在丑陋的方式:(。我做了很多的如果 - >不是这实在是uglly,我想补充一样,如果一些新的规则,什么都日期是超过一年我希望把字符串像过去一年左右....我真的需要添加丑陋逻辑。

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

如果有比IFS的一千一些游泳者的做法?如果不是由于任何办法,至少我会停止搜索沐浴液

if there some bather approach than thousand of ifs ? if not thanks any way at least I will stop searching for bather solution

任何建议,片段或因此将AP preciated

any suggestions , snippet or so will be appreciated

感谢

推荐答案

我一般用这个方便的Java库的相对时间格式。 http://ocpsoft.com/$p$pttytime/

I usually use this handy java library for Relative Time formatting. http://ocpsoft.com/prettytime/

阅读全文

相关推荐

最新文章