Reputation: 424
I am doing Json parsing and retrieving a Date
from it. I am getting in this format 2012-07-24
but i want to display it in this format Tuesday July 24, 2012
.
Can anybody suggest how I can achieve this?
Upvotes: 0
Views: 1729
Reputation: 29199
You need to use SimpleDateFormat for this purpose, do as follows:
SimpleDateFormat smf=new SimpleDateFormat("yyyy-MM-dd");
Date dt=smf.parse(strDate, 0);
smf= new SimpleDateFormat("EEEE MMMM dd,yyyy");
String newFt=smf.format(dt);
Upvotes: 0
Reputation: 13805
You can try
String date = "2012-07-24";
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat df2 = new SimpleDateFormat("EEE MMM dd, yyyy");
date = df2.format(format.parse(yourdate));
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 1
Reputation: 21191
use this below method
SimpleDateFormat dfDate = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dfDate_day= new SimpleDateFormat("EEEE MMMM dd, yyyy");
public String formatTimeDay(String str)
{
java.util.Date d = null;
try {
d = dfDate.parse(str);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
str = dfDate_day.format(d);
return str;
}
usage ====> formatTimeDay("2012-07-24");
Here
EEEE =====> day name (like Sunday, Monday)
MMMM =====> month name(like January, March)
dd =====> day number of the present month
yyyy =====> present year
Upvotes: 0
Reputation: 3370
Use
String s;
Format formatter;
// vvvvvvvvvv Add your date object here
Date date = new Date("2012-07-24");
formatter = new SimpleDateFormat("EEEE MMMM dd, yyyy");
s = formatter.format(date);
System.out.println(s);
Upvotes: 1
Reputation: 7625
You can use SimpleDateFormat to parse and format the date. On the JavaDoc are lots of examples: http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
Upvotes: 2