b85411 b85411 - 10 months ago 37
Java Question

How to get proper written date using SimpleDateFormat in Java

I have this:

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date result = dateFormat.parse(this.getCreatedTime());

Basically I want to convert a string like "2016-09-27T09:19:57Z" into something like "September 27, 2016 at 9:19 AM".

If I use the code above I end up with a
object, but all the methods are deprecated. So how do I achieve this?

Answer Source

You can use DateFormat again as @Thomas wrote:

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date inputDate = inputFormat.parse(this.getCreatedTime());
DateFormat outputFormat = new SimpleDateFormat("outputFormat");
String output = outputFormat.format(inputDate);