i want convert date in different format.
for example,
string fromdate = "2011-04-22"; want convert fromdate "22nd apr, 2011"
how can this?
thanks in advance
what want little tricky because of "nd" in 22nd. depending on day it'll need different suffix. simpledateformat
doesn't support formatting this. you'll have write additional code it. here's example, it's limited working in locales us:
simpledateformat fromformat = new simpledateformat("yyyy-mm-dd"); simpledateformat toformat = new simpledateformat("d'__' mmm, yyyy"); string fromdate = "2011-04-22"; date date = fromformat.parse(fromdate); string todate = toformat.format(date); calendar cal = calendar.getinstance(); cal.settime(date); int day = cal.get(calendar.day_of_month); if (day % 10 == 1 && day != 11) { todate = todate.replaceall("__", "st"); } else if (day % 10 == 2 && day != 12) { todate = todate.replaceall("__", "nd"); } else if (day % 10 == 3 && day != 13) { todate = todate.replaceall("__", "rd"); } else { todate = todate.replaceall("__", "th"); } system.out.println(todate);
Comments
Post a Comment