Home> Java> javaTutorial> body text

How to format date in java

王林
Release: 2020-05-17 16:22:46
Original
3791 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!