Java 日期<=>时间戳
/**
* 将时间戳解析为字符串日期
*
* @param timeDate
* @return
*/
@SuppressLint("SimpleDateFormat")
public static String requireDate(long timeDate) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(timeDate);
return simpleDateFormat.format(date);
} catch (Exception e) {
return "";
}
}
/**
* 将字符串日期解析成时间戳
*
* @param timeStr
* @return
*/
@SuppressLint("SimpleDateFormat")
public static long requireLongTime(String timeStr) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(timeStr);
return date.getTime();
} catch (Exception e) {
return 0L;
}
}
FlowLiver Notes

浙公网安备 33010602011771号