我正在获取一个日期表单服务器
Thu Apr 27 2023 19:08:00 GMT-0700 (Pacific Daylight Time)
我正在尝试将其转换为 "MMM dd, yyyy hh:mm a"
,它与 SimpleDateFormate
一起工作正常,但是 SimpleDateFormat
返回到 String
我想要 java.util.Date
格式。这是场景-
从服务器我得到 -
java.util.Date (Thu Apr 27 2023 19:08:00 GMT-0700 (Pacific Daylight Time))
我正在使用
"MMM dd, yyyy hh:mm a"
将其转换为 SimpleDateFormate
,它以 String
格式返回日期
预期:日期应为
java.util.Date ("MMM dd, yyyy hh:mm a")
格式。
我不确定我是否可以使用现代日期类,因为我正在处理的代码是单体代码和旧代码。
我试过下面-
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, locale);
String formattedDate = (date == null) ? "" : formatter.format(date); // This gives the expected format in String
formatter.parse(formattedDate); // value changes back when I convert it to java.util.date.