1、简单的时间戳转换
public static void main(String[] args) {
Long time = 1715852364117L;
Date date = new Date(time); // 创建一个Date对象,将时间戳传入Date对象
System.out.println("时间戳格式:"+time);
System.out.println("转换后日期:"+date);
}
1、时间格式化
在数据处理中遇到日期格式不对的数据 23/3/2022 16:23:32 如何进行处理?
解决方案:
对日期进行格式化处理
public String timeFormat(String date) {
String InputFormat = "dd/MM/yyyy HH:mm:ss";
String OutFormat = "yyyy/MM/dd HH:mm:ss";
try {
SimpleDateFormat simpleInputFormat = new SimpleDateFormat(InputFormat);
SimpleDateFormat simpleOutFormat = new SimpleDateFormat(OutFormat);
Date Out = simpleInputFormat.parse(date);
OutFormat = simpleOutFormat.format(Out);
} catch (ParseException e) {
e.printStackTrace();
}
return OutFormat
}
2、时间戳转换