I have the following string:
Mon Sep 14 15:24:40 UTC 2009
I need to format it into a string like this:
14/9/2009
How do I do it in Java?
I have the following string:
Mon Sep 14 15:24:40 UTC 2009
I need to format it into a string like this:
14/9/2009
How do I do it in Java?
One liner in java 8 and above.
You can use SimpleDateFormat class to convert the string you have to a date object. The date format can be given in the constructor. The format method converts the string to a date object.
After getting the date object, you can format it in the way you want.
Use
SimpleDateFormat
(click the javadoc link to see patterns) to parse the string in one pattern to a fullworthyDate
and use another one to format the parsedDate
to a string in another pattern.