This question already has an answer here:
- Java string to date conversion 13 answers
I got format like this
25 Jul 2015 07:32:16
and I want it like this
2015-07-25 07:32:16
How can I do it using java?
This question already has an answer here:
I got format like this
25 Jul 2015 07:32:16
and I want it like this
2015-07-25 07:32:16
How can I do it using java?
You could use two
SimpleDateFormat
s - one to parse the string into aDate
instance and the other to format it to your desired output.You simply need to have two date formatters, one to parse your date in the source format and another to format it in the target format. It goes like this:
You can find an executable version of this code shared here
Look at SimpleDateFormat
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
It can be used to parse a string to a date
Java string to date conversion
And then used to take that date and reparse it as a different formatted string
http://examples.javacodegeeks.com/core-java/text/java-simpledateformat-example/
something like this