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
    }
}

java中String转Date与Date转String

相关文章:

  • 2021-09-15
  • 2021-11-05
  • 2022-12-23
  • 2021-12-27
  • 2022-03-05
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-15
  • 2021-10-02
  • 2021-11-04
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案