How to get the current time and convert the time format in java

Convert the time to the specified format

Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(simpleDateFormat.format(date));

The date time format before
Insert picture description here
conversion is converted to yyyy-MM-dd HH:mm:ss time format
Insert picture description here

To convert the time format to another time format, just modify the time format yyyy-MM-dd HH:mm:ss in SimpleDateFormat to the time format you need,
such as:
ddmmyyyy
dd/mm/yyyy
mm/dd/yyyy
dd -mm-yyyy
mm-dd-yyyy
Month dd yyyy

Guess you like

Origin blog.csdn.net/Hambur_/article/details/110367713