import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date time = new Date();//调用Date对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");//调用simpledateformat对象 ,设置格式
String date = sdf.format(time);
System.out.println(date);
}
}
simpledateformat的作用:使输出的日期内容格式化,按照需要的样式输出
如果不用simpledateformat,也可以获取到当前的日期,但是日期格式固定为Tue Aug 22 10:02:31 CST 2023
浙公网安备 33010602011771号