时间戳(long)—>Date(String)
//时间格式,HH是24小时制,hh是1~12小时制(1~12)
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");//yyyy-MM-dd HH:mm:ss
String timestamp=1616138930;
long date_temp = Long.valueOf(timestamp);
String date_string = sdf.format(new Date(date_temp * 1000L));
System.out.println(date_string)
Date(String)—>时间戳(long)
public long getDate() {
String dateStr = "2021-03-24";
long date = 0;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}