String srt="2006-09-07 08:00:00"
怎么用
 SimpleDateFormat myFmt=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
myFmt.parse(str);
总是报错呢

解决方案 »

  1.   

    String str="2006-09-07 08:00:00";
    SimpleDateFormat myFmt=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    myFmt.parse(str);
      

  2.   

    没有啊,我这里不会报错啊,是不是你什么地方没有写好啊
    还有,myFmt.parse(str);
    这句话是会抛出异常的,你必须要放它入到try{}catch块里面,或者你的方法也声明抛出异常
      

  3.   

    try {
       String str = "2006-09-07 08:00:00";
       SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       myFmt.parse(str);
    } catch (ParseException p) {}