开发者

Android load timezone too long: Loaded time zone names for en_US

开发者 https://www.devze.com 2023-01-19 17:44 出处:网络
Dear all, i just code a snippet code to get date time string as below: public static String getCurrentDate(){

Dear all, i just code a snippet code to get date time string as below:

public static String getCurrentDate(){
    Locale.setDefault(Locale.US);
    Date date = new Date();
    String strDate = date.toString();
    return strDate;
}
开发者_Python百科

But problem is it take too long time (about 2 seconds) to convert from Date to string, Logs:

10-11 17:52:51.733: INFO/Resources(6835): Loaded time zone names for en_US in 2107ms.

Could you please give me a solution how to increase performance of this method

Update for solution: I just found an solution by tronman at topic: How do you format date and time in Android? As below:

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


Yet another solution is to use SimpleDateFormat with default locale

new SimpleDateFormat("dd/MM", Locale.getDefault());
0

精彩评论

暂无评论...
验证码 换一张
取 消