springboot(三)———解决 8/24/2022 6:00类型转换为2022-08-24 06:00:00.0(MM/dd/yyyy H:mm与yyyy-MM-dd HH:mm:ss转换)

输入
在这里插入图片描述
输出
在这里插入图片描述

代码

String datastring = "8/24/22 6:00";
String[] arrDate = datastring.split("/", 3);
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(arrDate[0] + "/" + arrDate[1] + "/20" + arrDate[2]);

SimpleDateFormat inputDateFormat = new SimpleDateFormat("MM/dd/yyyy H:mm");
SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date inputDate = inputDateFormat.parse(stringBuffer.toString());
Timestamp timestamp = Timestamp.valueOf(outputDateFormat.format(inputDate));
System.out.println(timestamp);

猜你喜欢

转载自blog.csdn.net/weixin_46457946/article/details/130540581