日期之间的转化关系:
1,获取当前系统时间
Date date = new Date();
2,Date转为DateTime
DateTime dateTime = new DateTime(date.getTime());
3,DateTime转为Date
Date date = dateTime.toDate();
4,获取日期格式,
DateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
5,Date转换为String类型格式
String dateStr = df.format(new Date());
工具类
/**
* 返回当前日期时间字符串
* 默认格式:yyyy-mm-dd hh:mm:ss
*
* @return String 返回当前字符串型日期时间
*/
public static String getCurrentTime() {
String returnStr = null;
SimpleDateFormat f = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Date date = new Date();
returnStr = f.format(date);
return returnStr;
}
/**
* 返回当前日期时间字符串
* 默认格式:yyyymmddhhmmss
*
* @return String 返回当前字符串型日期时间
*/
public static BigDecimal getCurrentTimeAsNumber() {
String returnStr = null;
SimpleDateFormat f = new SimpleDateFormat(“yyyyMMddHHmmss”);
Date date = new Date();
returnStr = f.format(date);
return new BigDecimal(returnStr);
}
/**
* 返回自定义格式的当前日期时间字符串
*
* @param format
* 格式规则
* @return String 返回当前字符串型日期时间
*/
public static String getCurrentTime(String format) {
String returnStr = null;
SimpleDateFormat f = new SimpleDateFormat(format);
Date date = new Date();
returnStr = f.format(date);
return returnStr;
}
/**
* 返回当前字符串型日期
*
* @return String 返回的字符串型日期
*/
public static String getCurDate() {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat simpledateformat = new SimpleDateFormat(“yyyy-MM-dd”);
String strDate = simpledateformat.format(calendar.getTime());
return strDate;
}
/**
* 返回指定格式的字符型日期
* @param date
* @param formatString
* @