我想以兩位數的格式顯示日期,我希望它是這樣的:當月或日是一個單一的數字時,4會顯示為04。如何實現呢?
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int day = c.get(Calendar.DAY_OF_MONTH);
int month = c.get(Calendar.MONTH);
if (month % 10 == 0) {
Place = 0 + month;
}
String Dates = year + "-" + Place + "-" + day;
Date.setText((Dates));
DecimalFormat mFormat= new DecimalFormat("00");
mFormat.format(Double.valueOf(year));
在你的例子中:
mFormat.setRoundingMode(RoundingMode.DOWN);
String Dates = mFormat.format(Double.valueOf(year)) + "-" + mFormat.format(Double.valueOf(Place)) + "-" + mFormat.format(Double.valueOf(day));