2013-06-22 110 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); 
相关问题