在SimpleDateFormat中将Date转换为String

A.G*_*A.G -1 java date simpledateformat

我想将日期格式转换为字符串,但字符串输出不会到来

  DateFormat currentDate = new SimpleDateFormat("dd MM yyyy ");
  String currDateString = String.valueOf(currentDate);
  System.out.println(currDateString);
Run Code Online (Sandbox Code Playgroud)

are*_*res 8

要格式化当前日期,您需要创建一个Date表示当前日期的实例,然后使用SimpleDateFormatto string 格式化它.

DateFormat dateFormat = new SimpleDateFormat("dd MM yyyy");
String currDateString = dateFormat.format(new Date());
System.out.println(currDateString);
Run Code Online (Sandbox Code Playgroud)