We can use the format() method in the date formatting class SimpleDateFormat, which can convert the date into a string in the specified format.
(Recommended video tutorial: java video)
The specific code is as follows:
Date date = new Date(); //获取当前的系统时间。 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss") ; //使用了默认的格式创建了一个日期格式化对象。 String time = dateFormat.format(date); //可以把日期转换转指定格式的字符串 System.out.println("当前的系统时间:"+ time);
Recommended tutorial: Getting started with java development
The above is the detailed content of How to format date in java. For more information, please follow other related articles on the PHP Chinese website!