2014-12-08 16 views
0

我需要以下時間戳轉換解析時間戳成可讀的格式(安卓)

String s = "08-12-2014 05:00:00" 

to a readable format like "Today 5am" 

敬請建議我怎麼能做到這一點,或者我可以使用libaries。

BTW這裏是我的嘗試

 String ago = hourly.getHour(j).time() ; 
      SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 
      Date d = inputFormat.parse(ago); 
      SimpleDateFormat outputFormat= new SimpleDateFormat("EEEE, MMMM dd, yyyy HH:mm a"); 
+0

我猜你正在尋找這個.. http://developer.android.com/reference/android/text/format/DateUtils.html#getRelativeDateTimeString %28android.content.Context,%20long,%20long,%20long,%20int 29% – Panther 2014-12-08 06:08:21

回答

0
 SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 
    SimpleDateFormat outputFormat= new SimpleDateFormat("EEEE, MMMM dd, yyyy HH:mm a"); 

    try { 
     Date oneWayTripDate = inputFormat.parse(datedata); 
    } catch (java.text.ParseException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
String datetime= outputFormat.format(oneWayTripDate); 
}