为什么这段代码不能输出呢?

img

换个类名试试,你这个Date可能跟自带的Date重复了
亲测可用

import java.sql.Date;
import java.text.SimpleDateFormat;

public class A {

  public static void main(String[] args) {
    Date date = new Date(System.currentTimeMillis());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日EEEHH:mm:ss");
    String date_str = date.toString();
    String date_format = sdf.format(date);
    System.out.println(date_str);
    System.out.println(date_format);
  }
}

img

代码11行,格式转换错误

感谢采纳,有问题继续交流!

img