使用Time.getCurrentTimezone()格式化日期,如系统格式

时间:2014-09-22 08:38:11

标签: android date date-format

我正在使用Time.getCurrentTimezone()获取当前时区,因此获取日期。 我正在这样格式化:

private void setDate() {
    Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();

    tvdate2.setText(today.monthDay + "-" + today.month + "-" + today.year);
}

如何根据系统设置格式化日期? 我没有设法通过SimpleDateFormat完成它......

1 个答案:

答案 0 :(得分:-1)

您可以使用SimpleDateFormat类以任何格式获得时间。请参考这个 Calendar cal = Calendar.getInstance(); String currentDate = cal.get(Calendar.DAY_OF_MONTH)+"/"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.YEAR); Date date = new SimpleDateFormat("dd/MM/yyyy HH:mm", Locale.ENGLISH).parse(currentDate);

相关问题