当前位置: 代码迷 >> Android >> Android中的时间日期格式怎么定义
  详细解决方案

Android中的时间日期格式怎么定义

热度:84   发布时间:2016-04-28 04:57:03.0
Android中的时间日期格式如何定义

1.如何保证日期格式与系统设定的一致:

Date date = new Date(location.getTime());DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());mTimeText.setText("Time: " + dateFormat.format(date));

注意此处应该应该用 android.text.format.DateFormat 而不是 java.text.DateFormat.

2. 如何自定义日期格式:

event.putExtra("starttime", "12/18/2012");SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");Date date = format.parse(bundle.getString("starttime"));

  相关解决方案