字符串转换时间方法

 1 public class ToTimes {
 2     
 3     
 4     static SimpleDateFormat[] sdfs = {
 5             new SimpleDateFormat("yyyy-MM-dd"),
 6             new SimpleDateFormat("yyyy/MM/dd"),
 7             new SimpleDateFormat("yyyy.MM.dd"),
 8             new SimpleDateFormat("yyyy年MM月dd日")
 9     };
10     
11     public static Date myDate(String sdate) throws Exception {
12         for(SimpleDateFormat d : sdfs) {
13             try {
14                 return d.parse(sdate);
15             } catch (ParseException e) {
16                 //e.printStackTrace();
17                 continue;
18             }
19         }
20         throw new Exception("格式不正确");
21     }
22 }

 

posted @ 2018-09-06 18:48  k丶灵  阅读(368)  评论(0编辑  收藏  举报