I want to convert a string “20/03/2022 12:33” to java.util.Date 20-MAR-22 in Java. Can any anybody help?
Asked
Active
Viewed 53 times
-2
-
2Read the Javadoc or grab a tutorial on date parsing and formatting, note that `java.util.Date` shouldn't be used anymore if you can help it (use the `java.time` API instead), try something, and if you still have problems post your attempt here. – Thomas May 31 '22 at 11:53
-
1There is no `java.util.Date` that can contain `"30-MAY-22"` exclusively… Use a `java.time.LocalDate` instead. – deHaar May 31 '22 at 11:56
-
1Duplicate of [this question](https://stackoverflow.com/questions/4772425/change-date-format-in-a-java-string) (hence the reopen vote, only to close as duplicate) – XtremeBaumer May 31 '22 at 13:27
-
Does this answer your question? [display Java.util.Date in a specific format](https://stackoverflow.com/questions/6262310/display-java-util-date-in-a-specific-format). @XtremeBaumer Fortunately we can list more than one original question when closing as a duplicate. – Ole V.V. May 31 '22 at 14:37
-
I strongly recommend you don’t use `java.util.Date`. That class is poorly designed and long outdated. Instead use `LocalDate` and `DateTimeFormatter`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. May 31 '22 at 14:39
-
Neither a `Date` nor a `LocalDate` can contain a format. So you are asking the impossible, – Ole V.V. May 31 '22 at 14:39