如何将日期Nov 8, 2005 11:33:15 AM 转换成2005-11-8 11:33:15

解决方案 »

  1.   

    看一下DateFormat
    先df.parse();然后 df.format();
      

  2.   

    Date da=new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    System.out.println(sdf.format(da));
      

  3.   

    测试代码:
    Date d = new Date();
    System.out.println(d); SimpleDateFormat sdf = new SimpleDateFormat();
    System.out.println( sdf.format(d));测试结果:
    Tue Nov 08 13:26:37 CST 2005
    05/11/08 13:26
      

  4.   


            String str="Nov 8, 2005 11:33:15 AM";
            DateFormat df = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a", Locale.ENGLISH);
            DateFormat style = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
            String result=df.format(new Date());
            System.out.println(style.format( df.parse(str)));
      

  5.   

    String str="Nov 8, 2005 11:33:15 AM";
            DateFormat df = new SimpleDateFormat("MMM d, yyyy hh:mm:ss a", Locale.ENGLISH);
            DateFormat style = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
            String result=df.format(new Date());
            System.out.println(style.format( df.parse(str)));把AM写为PM看看 !!
    DateFormat style = new SimpleDateFormat("yyyy-MM-dd k:mm:ss",
      

  6.   

    public static String toDateString(Date date, String toFormat)
        {
            GregorianCalendar gc = new GregorianCalendar();
            SimpleDateFormat df = new SimpleDateFormat(toFormat);
            df.setTimeZone(gc.getTimeZone());
            String toDateString = df.format(date);
            return toDateString;
        }