package com.my.demo;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DemoTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Date date=new Date();
System.out.println(date);
SimpleDateFormat sdf1=new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf3=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf4=new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
System.out.println(sdf1.format(date));
System.out.println(sdf2.format(date));
System.out.println(sdf3.format(date));
System.out.println(sdf4.format(date));
}
}
运行结果:
Fri Oct 30 23:22:05 CST 2020
20201030
2020-10-30
2020-10-30 23:22:05
2020年10月30日23时22分05秒