//字符串转换为时间戳
public static Long convertStrToStamp(String str,String format){
DateTimeFormatter ftf = DateTimeFormatter.ofPattern(format);
LocalDateTime parse = LocalDateTime.parse(str, ftf);
System.out.println(parse);
long l = parse.toInstant(ZoneOffset.of("+8")).toEpochMilli();//转换为时间戳
return l;
}
//字符串转换为时间戳 第二种方法
String recordTime="2020年11月24日 15:22:11";
String pattern="yyyy年MM月dd日 HH:mm:ss"
LocalDateTime parse = LocalDateTime.parse(recordTime, pattern);
Timestamp timestamp = Timestamp.valueOf(parse);
long stamp=timestamp.getTime();
//时间戳转换为时间格式
long stamp=时间戳;
LocalDateTime time2 =LocalDateTime.ofEpochSecond(stamp/1000,0,ZoneOffset.ofHours(8));//时间戳转换为字符串