问题
Is it possible to remove the "0" in January 04, 2012?
I am currently using the following Java to get the date format like
Monday, January 04, 2012
I would like for it to look like
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);
回答1:
SimpleDateFormat formatter = new SimpleDateFormat("EEEE', 'MMMM d', ' yyyy");
Should do it (one 'd' instead of two)?
http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
回答2:
You can get a String without "0" in front of a number just by doing this :
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);
来源:https://stackoverflow.com/questions/8836294/remove-leading-0-in-day-of-month-simpledateformat