Home  >  Article  >  Java  >  How to format date in java

How to format date in java

王林
王林Original
2020-05-17 16:22:463869browse

How to format date in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn