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));
Community
  • 1
  • 1
NguyenDat
  • 4,129
  • 3
  • 46
  • 46
  • duplicate of http://stackoverflow.com/questions/8881142/simpledateformat-takes-too-long-when-the-time-zone-is-included – Somatik Aug 18 '12 at 15:16
  • If you have an answer, why not post it separately and mark it as accepted answer? – Kuitsi Feb 22 '13 at 14:30

1 Answers1

0

Yet another solution is to use SimpleDateFormat with default locale

new SimpleDateFormat("dd/MM", Locale.getDefault());
iutinvg
  • 3,479
  • 3
  • 21
  • 18