SimpleDateFormat类的parse(String source)方法和format(Date date)方法
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void main(String[] args) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM Date date = simpleDateFormat.parse("2019-09-02"); System.out.println(date); //Mon Sep 02 00:00:00 CST 2019 System.out.println(simpleDateFormat.format(date)); //2019-09-02 } }