【DateFormat类方法的使用】 使用SimpleDateFormat类,把2018-03-04转换为2018年03月04日。

package day_01_test;

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

/*6、[简答题]
【DateFormat类方法的使用】

使用SimpleDateFormat类,把2018-03-04转换为2018年03月04日。*/
public class Test06 {
    public static void main(String[] args) throws ParseException {

        DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
        Date date = df1.parse("2018-03-04");
        DateFormat df2 = new SimpleDateFormat("yyyy年MM月dd日");
        String str = df2.format(date);
        System.out.println(str);
    }
}
posted @ 2022-03-26 14:41  不只是智能hello  阅读(56)  评论(0)    收藏  举报