- For the month of September:
- M -> 9
- MM -> 09
- MMM -> Sep
- MMMM -> September
- For 7 minutes past the hour:
- m -> 7
- mm -> 07
- mmm -> 007
- mmmm -> 0007
- Examples for April 6, 1970 at 3:23am:
- "MM/dd/yy h:mmaa" -> "04/06/70 3:23am"
- "MMM dd, yyyy h:mmaa" -> "Apr 6, 1970 3:23am"
- "MMMM dd, yyyy h:mmaa" -> "April 6, 1970 3:23am"
- "E, MMMM dd, yyyy h:mmaa" -> "Mon, April 6, 19703:23am&
- "EEEE, MMMM dd, yyyy h:mmaa" -> "Monday, April 6, 1970 3:23am"
- "'Noteworthy day: 'M/d/yy" -> "Noteworthy day: 4/6/70"
1.如何保证日期格式与系统设定的一致:
<code>Date date = new Date(location.getTime()); DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext()); mTimeText.setText("Time: " + dateFormat.format(date));</code>
注意此处应该应该用 android.text.format.DateFormat 而不是 java.text.DateFormat.
2. 如何自定义日期格式:
<code>event.putExtra("starttime", "12/18/2012"); SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); Date date = format.parse(bundle.getString("starttime"));</code>