更新日期格式2014-11-26(yyyy-mm-dd)到11月26,2014在android?

Ree*_*ena 0 android date

我可以将我的日期格式2014-12-09更改为MMM dd,yyyy(12月09,2014喜欢这个.)但它显示2014年1月9日而不是12月09,2014.如何显示Dec 09,2014?请指导我.

我的代码是,

String strStartDate = "2014-12-09";

            readFormat = new SimpleDateFormat("yyyy-mm-dd");
            writeFormat = new SimpleDateFormat("MMM dd,yyyy");

            try {
                startDate = readFormat.parse(strStartDate);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            viewHolder.txtStartDate
                    .setText(writeFormat.format(startDate));
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Pra*_*asa 6

试试以下代码:

String date = "2014-11-25";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
Date testDate = null;
try {
    testDate = sdf.parse(date);
}catch(Exception ex){
    ex.printStackTrace();
}
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd,yyyy");
String newFormat = formatter.format(testDate);
System.out.println(".....Date..."+newFormat);
Run Code Online (Sandbox Code Playgroud)