I want this format 6 Dec 2012 12:10
String time = "2012-12-08 13:39:57 +0000 ";
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
Date date = sdf.parse(time);
System.out.println("Time: " + date);
You need to first parse your date string (Use DateFormat#parse()
method) to get the Date
object using a format that matches the format of date string
.
And then format that Date object (Use DateFormat#format()
method) using the required format in SimpleDateFormat
to get string.
String time = "2012-12-08 13:39:57 +0000";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse(time);
String str = new SimpleDateFormat("dd MMM yyyy HH:mm:ss").format(date);
System.out.println(str);
Output: -
08 Dec 2012 19:09:57
Z
in the first format is for RFC 822 TimeZone to match +0000
in your date string. See SimpleDateFormat
for various other options to be used in your date format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With