格式化时间---SimpleDateFormate

java中使用SimpleDateFormate可以来格式化时间

指定格式,似乎是万能的qaq

代码:

 1 package UUID;
 2 
 3 import java.text.SimpleDateFormat;
 4 import java.util.Date;
 5 
 6 public class SDF {
 7     private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
 8     private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年-MM月-dd日");
 9     private static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy年-MM月-dd日 HH:mm:ss");
10     public static void main(String[] args) {
11         String date1 = sdf1.format(new Date()); //20200815
12         String date2 = sdf2.format(new Date()); //2020年-08月-15日
13         String date3 = sdf3.format(new Date()); //2020年-08月-15日 10:54:00
14         System.out.println(date1+'\n'+date2+'\n'+date3);
15     }
16 
17 }

 

posted @ 2020-08-17 10:16  良夜  阅读(284)  评论(0编辑  收藏  举报