DateFormat类、SimpleDateFormat子类、format、parse方法小练习

/*
使用SimpleDateFormat类,把2018-03-04转换为2018年03月04日。
 */
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Format {
    public static void main(String[] args) throws ParseException {
        DateFormat sdf = new SimpleDateFormat("yy-MM-dd");
        Date date = sdf.parse("2018-03-04");
        System.out.println(date);
        System.out.println("------------------------------");
        DateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日");
        String str = sdf1.format(date);
        System.out.println(str);
    }
}

猜你喜欢

转载自blog.csdn.net/Qioooba/article/details/88979733