/*** 获取当前日期年月日时分秒yyyy-MM-dd HH:mm:ss
*
*@return
*/
public staticString getDateTime() {
SimpleDateFormat simpleFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now= newDate();returnsimpleFormat.format(now);
}/*** 获取当前日期年月日时分秒yyyy-MM-dd*/
public staticString getDateYMD() {
SimpleDateFormat simpleFormat= new SimpleDateFormat("yyyy-MM-dd");
Date now= newDate();returnsimpleFormat.format(now);
}/*** 将string日期 转为 date*/
public staticDate StrToDate(String str) {
SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date= null;try{
date=format.parse(str);
}catch(ParseException e) {
e.printStackTrace();
}returndate;
}/*** @Title: getTimeByMOnthAfterDay 参数时间date 转为对应格式
*@param:@paramdate 要转换的时间
*@param:@paramformatstring 格式"yyyy-MM-dd HH:mm:ss", "yyyy-M-d H:m:s", "yyyy-MM-dd H:m:s", "yyyy-M-d HH:mm:ss"
*@param:@return*@return: String*/
public staticString getTimeByTransformation(Date date, String formatstring) {
Calendar cal=Calendar.getInstance();
cal.setTime(date);
SimpleDateFormat simpleFormat= newSimpleDateFormat(formatstring);returnsimpleFormat.format(cal.getTime());
}/*** 参数时间当月最后一天
*@param:@paramdate 要转换的时间
*@param:@paramformatstring 格式"yyyy-MM-dd HH:mm:ss", "yyyy-M-d H:m:s", "yyyy-MM-dd H:m:s", "yyyy-M-d HH:mm:ss"*/
public staticString getTimeByMOnthAfterDay(Date date, String formatstring) {
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(Calendar.DAY_OF_MONTH));
SimpleDateFormat simpleFormat= newSimpleDateFormat(formatstring);returnsimpleFormat.format(cal.getTime());
}/*** 参数时间当月第一天
**@param:@paramdate 要转换的时间
*@param:@paramformatstring 格式"yyyy-MM-dd HH:mm:ss", "yyyy-M-d H:m:s", "yyyy-MM-dd H:m:s", "yyyy-M-d HH:mm:ss"*/
public staticString getTimeByMOnthFirstDay(Date date, String formatstring) {
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH,1);
SimpleDateFormat simpleFormat= newSimpleDateFormat(formatstring);returnsimpleFormat.format(cal.getTime());
}