date4j - Java日期时间处理类


BSD
跨平台
Java

软件简介

date4j是一个用于简化日期和时间操作的Java工具。可以替换java.util.Date。

示例代码:

DateTime dateAndTime = new DateTime("2010-01-19 23:59:59");  
DateTime dateAndTime = new DateTime("2010-01-19 23:59:59.123456789");  
DateTime dateOnly = new DateTime("2010-01-19");  
DateTime timeOnly = new DateTime("23:59:59");  
DateTime dateOnly = DateTime.forDateOnly(2010,01,19);  
DateTime timeOnly = DateTime.forTimeOnly(23,59,59,0);

DateTime dt = new DateTime("2010-01-15 13:59:15");  
boolean leap = dt.isLeapYear(); //false  
dt.getNumDaysInMonth(); //31  
dt.getStartOfMonth(); //2010-01-01, 00:00:00.000000000  
dt.getEndOfDay(); //2010-01-15, 23:59:59.999999999  
dt.format("YYYY-MM-DD"); //formats as '2010-01-15'  
dt.plusDays(30); //30 days after Jan 15  
dt.numDaysFrom(someDate); //returns an int  
dueDate.lt(someDate); //less-than  
dueDate.lteq(someDate); //less-than-or-equal-to