Android将月份作为两位数字

Luk*_*ley 1 android date

嗨有谁知道如何将月份作为两位数的数字,例如04或05?

sil*_*war 11

试试这个

 dateFormat = "MM";
 SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
 String month = sdf.format(date);
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请在Android中查看格式化月份

还要检查SimpleDateFormat.

  • 使用String.format("%02d",monthValue)添加前导零 (2认同)