如题:我现在有串数字20110414152200我想把它转换成时间格式的。就是这个样子:2011-04-14 15:22:00.找高手帮忙啊!最好把代码附上。谢谢。

解决方案 »

  1.   

    Date d = new SimpleDateFormat("yyyyMMddhhmm").parse("2011041415220");
    String s = new SimpleDateFormat("yyyy-MM-dd hh:mm").format(d);

    System.out.println(s);
      

  2.   


    String time = "20110414152200";
    SimpleDateFormat df1 = new SimpleDateFormat("yyyyMMddHHmmss");
    SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
    System.out.println(df2.format(df1.parse(time)));
    } catch (ParseException e) {
    //TODO 日期格式不正确
    }
      

  3.   

     
    Calendar c =Calendar.getInstance().setTimeInMillis(2011041415220);
    Date d = c.getTime();