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;
}