日期类型/字符串类型互转

 1    /**
 2      * 日期格式转字符串
 3      * */
 4     public static String test01(){
 5         DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
 6         return sdf.format(new Date());
 7     }
 8 
 9     /**
10      * 字符串转日期
11      * */
12     public static Date test02() throws ParseException {
13         DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
14         String s = "2020-09-11 10:19:08";
15         return sdf.parse(s);
16     }

 

posted @ 2020-09-11 22:25  Zr0118  阅读(80)  评论(0编辑  收藏  举报