Android examples for java.lang:String Format
get Date String using String.format
import java.util.Calendar; public class Main { public static String getDateString() { Calendar c = Calendar.getInstance(); String Datestring = "" + c.get(Calendar.YEAR) + String.format("%02d", (c.get(Calendar.MONTH) + 1)) + String.format("%02d", c.get(Calendar.DAY_OF_MONTH)) + String.format("%02d", c.get(Calendar.HOUR_OF_DAY)) + String.format("%02d", c.get(Calendar.MINUTE)) + String.format("%02d", c.get(Calendar.SECOND)); return Datestring; }//from w ww. j a va 2 s . com }