最好写一个方法有个传入参数麻烦大家啊,我数据结构确实不好啊

解决方案 »

  1.   

    看不出 有什么联系出来
    如果是 yyyyMMdd HH:mm
    转化为 yyyy-MM-dd HH:mm
    最简单的字符串转化:
    private String getStr(String in){
    if(null==in)
    return null;
    if(in.length()<14)
    return in;
    return in.subString(0,4)+"-"+in.subString(4,6)+"-"+in.subString(6,8)+in.subString(8.in.length);}
      

  2.   

    或者时间转化
    public static void main(String[] args) {

    //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
    System.out.println(getStr("20070903 09:00"));
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    }


    }
    private static String getStr(String in)throws Exception{
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm");

    Date d1 =sdf.parse(in);

    sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    return sdf.format(d1);

    }
      

  3.   


    public String FmtDateTime(String dateTime) {
    if (dateTime!=null&&dateTime.length() == 14) {
    return dateTime.substring(0, 4) + "-" + dateTime.substring(4, 6)
    + "-" + dateTime.substring(6, 8) + dateTime.substring(8);
    }
    return dateTime;
    }
      

  4.   

    Date date = new Date();String pattern = "yyyy-MM-dd HH:mm:ss z";SimpleDateFormat df = new SimpleDateFormat(pattern);System.out.println(df.format(date));