【蛻變之路】第21天 時間格式轉換 (2019年3月11日)

    Hello,大家好!我是程序員阿飛!今天主要學習的內容是:將世界標準時間(字符串)轉換成特定格式時間(字符串)。好了,直接進入正題。

    1、代碼示例

         /***

         * 將世界標準時間(字符串)轉成特定格式時間(字符串)

         * @time  : 2019-03-11 15:43

         * @author: wnf

         * @descript:

         */

        public static String format(String time){

                   Date d2 = null;

                   String format= null;

                if(time!=null && !"".equals(time)){

                          SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CST' yyyy", Locale.ENGLISH);

                          SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                          try {

                               d2 = sdf.parse(time);

                              format = formatter.format(d2);

                          } catch (ParseException e) {

                               e.printStackTrace();

                          }

                          return format;

                }

                return format;

        }

        

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章