java - Convert date to friendly format using SimpleDateFormat -
i trying format date such mon jul 28 00:00:00 cdt 2014
bit more user friendly, such mon 6/28
. doing wrong?
code:
string date_string = "mon jul 28 00:00:00 cdt 2014"; simpledateformat inputformatter = new simpledateformat("ccc lll f hh:mm:ss zzz yyyy"); //please notice capital m simpledateformat outputformatter = new simpledateformat("ccc lll/yyyy"); try { date date = inputformatter.parse(date_string); string text = outputformatter.format(date); system.out.println(text); } catch (parseexception e) { e.printstacktrace(); }
when use system.out.println see outputformatter set to, result is: sun jan/2015
try this..
change this..
simpledateformat outputformatter = new simpledateformat("ccc lll/yyyy");
to
simpledateformat outputformatter = new simpledateformat("eee m/dd");
eee
--> mon
eeee
--> monday
mm
--> 06
m
--> 6
dd
--> 28
edit
simpledateformat inputformatter = new simpledateformat("eee mmm dd hh:mm:ss zzz yyyy");
demo
Comments
Post a Comment