【发布时间】:2011-04-23 18:18:07
【问题描述】:
亲爱的,我只是编写了一个 sn-p 代码来获取日期时间字符串,如下所示:
public static String getCurrentDate(){
Locale.setDefault(Locale.US);
Date date = new Date();
String strDate = date.toString();
return strDate;
}
但问题是从日期转换为字符串需要很长时间(大约 2 秒),日志:
10-11 17:52:51.733: INFO/Resources(6835): Loaded time zone names for en_US in 2107ms.
能否请您给我一个解决方案如何提高此方法的性能
解决方案更新: 我刚刚在主题上找到了 tronman 的解决方案: How do you format date and time in Android? 如下:
Date date = new Date();
java.text.DateFormat dateFormat =
android.text.format.DateFormat.getDateFormat(getApplicationContext());
mTimeText.setText("Time: " + dateFormat.format(date));
【问题讨论】:
-
如果您有答案,为什么不单独发布并将其标记为已接受的答案?