2012-01-12 20 views
13

是否可以在2012年1月4日刪除「0」?在一個月中刪除領先的「0」SimpleDateFormat

我目前使用下面的Java得到的日期格式類似

Monday, January 04, 2012 

我想它看起來像

Monday, January 4, 2012 

    Date anotherCurDate = new Date(); 

    SimpleDateFormat formatter = new SimpleDateFormat("EEEE', 'MMMM dd', ' yyyy"); 
    final String formattedDateString = formatter.format(anotherCurDate); 

final TextView currentRoomDate = (TextView) this.findViewById(R.id.CurrentDate); 

回答

33
SimpleDateFormat formatter = new SimpleDateFormat("EEEE', 'MMMM d', ' yyyy"); 

應該這樣做(一個「d」而不是兩個)?

http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

+0

當然,這將是容易的。我認爲會有一些後期處理來修復它。謝謝,我現在會測試。 – Denoteone 2012-01-12 14:04:26

+0

嘿嘿,它被稱爲'簡單'日期格式化器的原因;)我添加了一個鏈接到它的文檔,以防萬一你沒有看到它。 – Jave 2012-01-12 14:07:17

+0

工作+1,我會在5分鐘內檢查問題 – Denoteone 2012-01-12 14:08:52

0

您可以只用這樣得到的號碼前沒有「0」的字符串:

Calendar today = Calendar.getInstance(); 
// If you want the day/month in String format 
String month = today.get(Calendar.MONTH)+""; 

// If you want the day/month in Integer format 
int monthInt = (int) Integer.parseInt(month);