org.apache.commons.lang.time
(2008-10-18 14:52:41) 标签: it |
好了,来看我在Common Lang中最后要讲的一个包:org.apache.commons.lang.time。这个包里面包含了如下5个类:
DateFormatUtils – 提供格式化日期和时间的功能及相关常量;
DateUtils – 在Calendar和Date的基础上提供更方便的访问;
DurationFormatUtils – 提供格式化时间跨度的功能及相关常量;
FastDateFormat – 为java.text.SimpleDateFormat提供一个的线程安全的替代类;
StopWatch – 是一个方便的计时器。
我们还是在一个例子中来看上述各个类的用法吧:
package sean.study.jakarta.commons.lang;
import java.util.Calendar;
import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.commons.lang.time.StopWatch;
public class DateTimeUsage {
}
以下是运行结果:
======= demoDateUtils ========
ISO_DATETIME_FORMAT: 2005-08-01T12:41:51
ISO_TIME_NO_T_FORMAT: 12:41:51
Custom FastDateFormat: 2005-08
Default format: Mon Aug 01 12:41:51 CST 2005
Round HOUR: Mon Aug 01 13:00:00 CST 2005
Truncate HOUR: Mon Aug 01 12:00:00 CST 2005
======= demoStopWatch ========
operationA used 1000 milliseconds.
具体的调用细节和完整的API请参阅Commons Lang的Javadoc。