I have a string "11/15/2013 08:00:00
", I want to format it to "11/15/2013
", what is the correct DateTimeFormatter
pattern?
I've tried many and googled and still unable to find the correct pattern.
edit: I am looking for Joda-Time DateTimeFormatter
, not Java's SimpleDateFormat..
Joda time
Create a
DateTimeFormatter
usingDateTimeFormat.forPattern(String)
Using Joda time you would do it like this:
Standard Java ≥ 8
Java 8 introduced a new Date and Time library, making it easier to deal with dates and times. If you want to use standard Java version 8 or beyond, you would use a DateTimeFormatter. Since you don't have a time zone in your
String
, a java.time.LocalDateTime or a LocalDate, otherwise the time zoned varieties ZonedDateTime and ZonedDate could be used.Standard Java < 8
Before Java 8, you would use the a SimpleDateFormat and java.util.Date
I think this will work, if you are using JodaTime:
I got part of this from here.
This works
I am adding this here even though the other answers are completely acceptable. JodaTime has parsers pre built in DateTimeFormat:
This is most of the options printed out with their format:
I have a very dumb but working option. if you have the String fullDate = "11/15/2013 08:00:00";
That should work easy and fast. :)