2013-06-22 111 views
0

我的模式爲26/03/2013。 Android中如何獲得像March 2013格式的等效月份和年份?我的約會是29-03-2017在Android中將日期轉換爲月份和年份

我想將此日期轉換爲年份和月份。

+0

檢查此[鏈接](http://stackoverflow.com/a/14081940/2345913),也可以使用[SimpleDateFormat的(HTTP://開發商。 android.com/reference/java/text/SimpleDateFormat.html) – CRUSADER

回答

1

像這樣:

try { 
    String dateString = "26/03/2013"; 
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); 
    Date date = sdf.parse(dateString); 

    SimpleDateFormat outputFormat = new SimpleDateFormat("MMMM yyyy"); 
    String formattedDate = outputFormat.format(date); 

    Log.d(TAG, "Got the date: " + formattedDate); 
} catch (ParseException e) { 
    e.printStackTrace(); 
} 
+0

不錯的答案。完善。 +1 – Raghunandan

+0

噢,你讓我臉紅! :) –

+0

thanx老兄。 :) – user2449062

0
String strdate = "26/03/2013";  
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); 
    Date yourdate = sdf.parse(str); 

SimpleDateFormat sdf = new SimpleDateFormat("MMMM yyyy"); 
    String yourfinaldate = sdf.format(yourdate); 
相關問題