1
votes

In my project ,I get json data from Server,there's a field named 'creat_at' in the json which style is like 'Wed Jun 20 11:01:05 +0800 2012'

How to change it to more easy-to-read style like '2012/06/20'?

(I have tried 'DateFormat.parse' but it dose not work: new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy").parse(dateString) cause java.text.ParseException: Unparseable date: "Wed Jun 20 11:00:53 +0800 2012")

2
Well if you can format it in the server end just use DateFormatterThihara

2 Answers

2
votes

See SimpleDateFormat API

Date date  = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy").parse(dateString);
String formattedDate = new SimpleDateFormat("yyyy/MM/dd").format(date);
1
votes

You need to try SimpleDateFormat

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
System.out.println(sdf2.format(sdf.parse("Wed Jun 20 11:01:05 +0800 2012")));

prints

2012/06/20

You may also need to set an approriate timezone.