1. 程式人生 > >時間相關的轉換匯總

時間相關的轉換匯總

add sta span spl start arr 字符串 array rtt

1 .String格式轉化為Date對象:

DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd");
Date date = fmt.parse("字符串");

2 .Date格式轉化為String對象:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startTime = sdf.format("日期");

3 .時間默認格式轉換為String

String datestr= "Mon Aug 15 11:24:39 CST 2016";//Date的默認格式顯示

Date date=new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK)).parse(datestr);

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

String str=sdf.format(date);

4 .工作遇到的時間轉換

//格式化
String replace = document_edge.get("timeseries").toString();
replace = replace.replace("[","");
replace=replace.replace("]", "");
List<String> dateList = new ArrayList<>();
if(null!=replace &&!"".equals(replace)){
String[] split = replace.split(", ");
for (String stringData : split) {
if(null!=stringData&&!"".equals(stringData)){
Date parse = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK).parse(stringData);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate=sdf.format(parse);
dateList.add(strDate); } } }
edgeDataJson.put("timeseries",dateList);

時間相關的轉換匯總