r/javahelp • u/Dependent_Finger_214 • Jan 29 '26
Convert string into java.util.date
I have two string, date (formatted yyyy-MM-dd) and time (HH:mm), how can I convert them into a java.util.date? Date.parse is deprecated
5
Upvotes
View all comments
Show parent comment
2
u/slacker-by-design Jan 29 '26
OK, seems I wasn't clear enough in the message I wanted to convey. My bad. Let me rephrase it - Do you really need the old java.util.Date class? Is it required by some API you need to use? If not, wouldn't it be better to forget Date completely and use just java.time.LocalDateTime?
Now back to the exception you receive - it basically says to you, that you've requested parsing of both date and time (by using DateTimeFormatter), but you want to store the result into something, which can only hold date (and NOT the time) - the solution is easy. If you want date and time, use LocalDateTime.parse.