luohzzz

导航

SimpleDateFormat类

![在这里插入图片描述](https://img-blog.csdnimg.cn/img_convert/babfebe93fdeccace348ae2951e967f8.png#pic_center)
~~~java
package Demo4;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatDemo {
public static void main(String[] args) throws ParseException {
//1、创建SimpleDateFormat对象
SimpleDateFormat adf = new SimpleDateFormat("yyyy/MM/dd");
//2、创建Date对象
Date date = new Date();
//3、格式化date,date使用SimpleDateFormat的格式
String str = adf.format(date);
System.out.println(str);

Date dat2 = adf.parse("2020/03/12");
System.out.println(dat2);
}
}

posted on 2021-05-08 09:45  luohzzz  阅读(41)  评论(0编辑  收藏  举报