首页 > 代码库 > 32 commons-lang包学习

32 commons-lang包学习

maven依赖

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>


一、DateUtils类

1、日期比较

public static boolean isSameDay(Date date1, Date date2): 是否是同一天,支持参数date和calendar
public static boolean isSameDay(Calendar cal1, Calendar cal2)
public static boolean isSameInstant(Date date1, Date date2): 是否是同一个UTC时间(long—) ,支持参数date和calendar
public static boolean isSameInstant(Calendar cal1, Calendar cal2)
public static boolean isSameLocalTime(Calendar cal1, Calendar cal2): 是否是同一个UTC时间(long—) ,支持参数calendar

/*************************************************************************************************************
public static Date parseDate(String str, String[] parsePatterns) 对字符串日期按照表达式进行转化,逐个顺序转化,如果都不满足,返回ParseException异常
private static Date parseDateWithLeniency(String str, String[] parsePatterns,
boolean lenient)

/************************************************************************************************************
public static Date addYears(Date date, int amount)   在date日期上增加年、月、周、日、时、分、秒、毫秒
public static Date addMonths(Date date, int amount)
public static Date addWeeks(Date date, int amount)
public static Date addDays(Date date, int amount)
public static Date addHours(Date date, int amount)
public static Date addMinutes(Date date, int amount)
public static Date addSeconds(Date date, int amount)
public static Date addMilliseconds(Date date, int amount)
public static Date add(Date date, int calendarField, int amount)  上述方法均调用此方法实现
/*************************************************************************************************************
public static Date setYears(Date date, int amount)   在date日期上设置年年、月、周、日、时、分、秒、毫秒
...省略
/*************************************************************************************************************
public static Calendar toCalendar(Date date)  date转成calendar
public static Date round(Date date, int field) 对date型日期根据field向上取  ,如field为Calendar.HOUR_OF_DAYMarch 30, 2003 01:10 rounds to March 30, 2003 01:00
public static Calendar round(Calendar date, int field)
public static Date round(Object date, int field)

 

public static Date truncate(Date date, int field)对date型日期根据field向下取整
public static Calendar truncate(Calendar date, int field)
public static Date truncate(Object date, int field)
 

还有部分未用过的,就不列举了



32 commons-lang包学习