String time =  "20081210162639";//所有时间都是这种格式表示年月日小时分秒想转成  2008-12-10 16:26:39,该如何转啊?

解决方案 »

  1.   

    String time =  "20081210162639";
    StringBuffer time2=new StringBuffer(time);
    String time3 = new String( time2.substring(0, 3)+"-" +
    time2.substring(4,5 )+"-" +
    time2.substring(6, 7)+" " +
    time2.substring(8, 9)+":" +
    time2.substring(10, 11));
      

  2.   

    刚才有点细节问题 呵呵,
    现在对了  String time =  "20081210162639";
    StringBuffer time2=new StringBuffer(time);
    String time3 = new String( time2.substring(0, 4)+"-" +
    time2.substring(4,6 )+"-" +
    time2.substring(6, 8)+" " +
    time2.substring(8, 10)+":" +
    time2.substring(10, 12)+":" +
    time2.substring(12, 14));
    System.out.println(time3);
      

  3.   

     DateFormat(now(),"yyyy-mm-dd hh:mm:ss") 
    使用DateFormat
      

  4.   

    SimpleDateFormat date = new SimpleDateFormat("yyyy.MM.dd"); String receivedTime = date.format(new Date(System.currentTimeMillis())); receivedTime = receivedTime.replaceAll("\\.", "");
            System.out.println(receivedTime);
            
            
            String a = "2008.11.24";
            String b = "2008.10.11";
             a =a.replaceAll("\\.", "");
            b= b.replaceAll("\\.", "");
            System.out.println(a+"  ss  "+b);楼主 看看这个
      

  5.   

    Date date= new SimpleDateFormat("yyyy/MM/dd/hh/mm/ss"); 
      

  6.   


    package org.leelin.common;import java.text.SimpleDateFormat;
    import java.util.Date;public class DateTester { /**
     * @param args
     */
    public static void main(String[] args) throws Exception{
    // TODO Auto-generated method stub
    String date="20081210162639";
    SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
    Date d=sdf.parse(date);
    SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd日 HH-mm-ss");
    String formatDate=sdf2.format(d);
    System.out.println(formatDate);
    }}
      

  7.   

    把SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    换成SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      

  8.   

    String time = "20081210162639";
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    System.out.println(df.parse(time).toLocaleString());