时间格式化Java类库 PrettyTime
fmms
13年前
PrettyTime是一个开源的时间格式化类库。它能够将时间格式成易于用户阅读的格式,如"12分钟前"、"2天前"、"至今3个月"等。易于使用。完全可定制,可以创建属于自己TimeUnit和TimeFormat对象。能够与JSF框架集成使用。 <br /> 示例代码: <pre class="brush:java; toolbar: true; auto-links: false;">import java.util.Date; import com.ocpsoft.pretty.time.PrettyTime; public class BasicJavaApp { public static void main(String[] args) { PrettyTime p = new PrettyTime(); System.out.println(p.format(new Date())); } }</pre> <pre class="brush:java; toolbar: true; auto-links: false;">package com.ocpsoft.pretty.time.i18n; import java.util.ListResourceBundle; public class Resources_de extends ListResourceBundle { private static final Object[][] CONTENTS = new Object[][] { { "CenturyPattern", "%n %u" }, { "CenturyFuturePrefix", "In " }, { "CenturyFutureSuffix", "" }, { "CenturyPastPrefix", "Vor " }, { "CenturyPastSuffix", "" }, { "CenturyName", "Jahrhundert" }, { "CenturyPluralName", "Jahrhunderten" } //... }; } @Override protected Object[][] getContents() { return CONTENTS; } }</pre> <br /> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1326938023624" target="_blank">http://www.open-open.com/lib/view/home/1326938023624</a></p>