Month without leading zeros in Android

user961389 picture user961389 · Dec 30, 2011 · Viewed 18.4k times · Source

Is there a way to format a Month without leading zeros in Java/Android?

I got this:

mTitleText.setText(String.format("Pick Date Time: %tm/%te/%tY %tk:%02d",
                mTime,mTime,mTime,mTime,minute)); 

And it returns 02/12/2012 13:23 when I want it to return 2/12/2012 13:23.

Answer

mxro picture mxro · Jan 24, 2013

For those interested in avoiding the lengthy JavaDocs:

Date mTime = new Date();  
String text = new SimpleDateFormat("M/d/yyyy hh:mm").format(mTime);

Using M instead of MM and d instead of dd will render the day of the month and month without leading zeros if possible.