`java.util.Date` from String 2021-07-28 21:36:34: not a valid representation
时间: 2024-04-30 21:20:30 浏览: 144
The error message you are seeing suggests that the string you are trying to parse into a `java.util.Date` object is not in a valid format.
By default, `java.util.Date` expects the input string to be in the format of "EEE MMM dd HH:mm:ss zzz yyyy". If the input string does not match this format, you will get a `ParseException`.
To parse a string in a different format, you can use a `SimpleDateFormat` object to specify the input format. Here's an example:
```
String dateString = "2021-07-28 21:36:34";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = dateFormat.parse(dateString);
```
This code creates a `SimpleDateFormat` object with the format "yyyy-MM-dd HH:mm:ss", which matches the format of the input string. It then calls the `parse` method on the `dateFormat` object to convert the string into a `Date` object.
Note that the `parse` method can also throw a `ParseException` if the input string does not match the specified format. You may want to handle this exception to provide a better error message to the user.
阅读全文