获取时间戳
public static Long getMillis1() {
return System.currentTimeMillis();
}
Date转时间戳
public static Long date2Millis(Date date) {
return date.getTime();
}
时间戳转Date
public static Long millis2Date(long millis) {
return new Date(millis);
}
日期字符串转时间戳
public static Long string2Millis(String dateStr, String formatStr) {
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
return simpleDateFormat.parse(dateStr).getTime();
} catch (Exception e) {
return 0L;
}
}
Calendar转时间戳
public static Long calendar2Millis(Calendar calendar) {
return calendar.getTime().getTime();
}