I\'m currently working on some simple project in Java
and I have date in the following string:
String dateString = \"Sun 7/14 03:44 AM 2013\";
The modern answer for the sake of completeness. While the other answers were good answers in 2013, Date
, DateFormat
and SimpleDateFormat
are now long outdated, and I recommend you replace them with their modern counterparts:
DateTimeFormatter parser
= DateTimeFormatter.ofPattern("EEE M/dd hh:mm a yyyy", Locale.ENGLISH);
LocalDateTime ldt = LocalDateTime.parse(dateString, parser);
The result is a LocalDateTime
of 2013-07-14T03:44
as expected.
The format pattern string is still the same, and the need for an English language locale is the same.