亲爱的所有人,我只是编写了一段代码以获得日期时间字符串,如下所示:
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.请你给我一个如何提高这种方法的性能的解决方案。
更新解决方案:我刚刚在主题:How do you format date and time in Android?上找到了tronman的解决方案,如下所示:
Date date = new Date();
java.text.DateFormat dateFormat =
android.text.format.DateFormat.getDateFormat(getApplicationContext());
mTimeText.setText("Time: " + dateFormat.format(date));发布于 2013-04-10 05:32:09
另一种解决方案是将SimpleDateFormat与默认区域设置结合使用。
new SimpleDateFormat("dd/MM", Locale.getDefault());https://stackoverflow.com/questions/3905545
复制相似问题