如何在Android中将日期时间从一种格式转换为另一种格式?

Nid*_*dhi 1 android android-date android-calendar

我想将日期和时间从"2014-11-25 14:30"格式转换为"2014年11月25日下午2:30".有人可以告诉你怎么做吗?

谢谢!

Pra*_*asa 6

试试以下代码:

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