//获取本地时间
public static String getCurrentDate() {
Date d = new Date();
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(d);
}
//时间戳转换成字符串
public static String getDateToString(long time) {
Date d = new Date(time);
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.format(d);
}
//字符串转换成时间戳
public static long getStringToDate(String time) {
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
try {
date = format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return date.getTime();
}
获取系统时间以及将时间戳转换成字符串,将字符串转换成时间戳
最新推荐文章于 2024-07-02 00:30:00 发布