import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * 
 */
public class CurrentDate {
    CurrentDate(){}
    private String crtDate="";    SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-mm-dd");
    Date today=new Date();
    crtDate=dateFormat.format(today);
    
}
这段代码有错吗?eclipse报错说Syntax error on token";",,expected

解决方案 »

  1.   

    最简单的更正:
    import java.text.SimpleDateFormat;
    import java.util.Date;
    /**
     * 
     */
    public class CurrentDate {
        CurrentDate(){}
        private String crtDate="";
        {
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-mm-dd");
        Date today=new Date();
        crtDate=dateFormat.format(today);
        }
    }
      

  2.   

    可以了 treeroot(旗鲁特) ,能说说为什么加个{}就可以了吗?
      

  3.   

    yyyy-mm-dd
    --> yyyy-MM-dd
    MM长大了!