日期:2014-05-20  浏览次数:20705 次

java日期格式
请问 Apr 22 2012 12:00AM 这种格式的日期怎么能转换成 yyyy-MM-dd hh:mm

------解决方案--------------------
如果是带有英文的这种日期格式的字符串采用默认的SimpleDateFormat是不能转换成Date的
时用小写的hh表示12时制的
Java code

try
    {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy hh:mma",Locale.ENGLISH);
        Date d=sdf.parse("Apr 22 2012 01:00PM ");
        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        System.out.println(sdf.format( d ));
        sdf = new SimpleDateFormat("yyyy-MM-dd hh:mma");
        System.out.println(sdf.format( d ));
    }catch (ParseException e) {
         e.printStackTrace();
    }