/**
*
* @Description: 获取当前时间 格式为yyyy-MM-dd HH:mm:ss
* @return
*/
public static String getCurrentDate() {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar rightNow = Calendar.getInstance();
return df.format(rightNow.getTime());
}
/**
* 通过时间秒毫秒数判断两个时间的间隔
* @param date1
* @param date2
* @return
*/
public static int differentDaysByMillisecond(String date1Str){
Date date1=StrToDate(date1Str,"yyyy-MM-dd HH:mm:ss");
int days = (int) ((new Date().getTime() - date1.getTime()) / (1000*3600*24));
return days;
}
/**
* 通过时间秒毫秒数判断两个时间的间隔
* @param date1
* @param date2
* @return
*/
public static int differentDaysByMillisecond(String date1Str,String date2Str){
Date date1=StrToDate(date1Str,"yyyy-MM-dd HH:mm:ss");
Date date2=StrToDate(date2Str,"yyyy-MM-dd HH:mm:ss");
int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
return days;
}
/**
* 字符串转换成日期
*
* @param str
* @return date
*/
public static Date StrToDate(String str, String formatStr) {
SimpleDateFormat format = new SimpleDateFormat(formatStr);
Date date = null;
try {
date = format.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
*
* @Description: 获取当前时间 格式为yyyy-MM-dd
* @return
*/
public static String getCurrentDate(String str) {
SimpleDateFormat df = new SimpleDateFormat(str);
Calendar rightNow = Calendar.getInstance();
return df.format(rightNow.getTime());
}
/**
* 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
*
* @param strDate
* @return
*/
public static Date strToDateLong(String strDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
/***
* 时间戳转时间
* 方法名: strToDateLong
* 描述: TODO(描述这个方法的作用)
* 参数: @param strDate
* 参数: @return
* 返回类型: Date
* 创建时间:2018年10月17日 上午10:48:47
*/
public static String longToDate(long timeStamp ) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//这个是你要转成后的时间的格式
String sd = sdf.format(new Date(timeStamp)); // 时间戳转换成时间
return sd;
}