4

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;
}

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));
2

1 Answer 1

0

Yet another solution is to use SimpleDateFormat with default locale

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.