android tip – don’t call toString() on a Date object!

I was seeing slowness in my android application (1.5) and noticed the following line in DDMS log

“Loaded time zone names for en_US in 7451ms.”

I couldn’t figure out from searching around what that was about and had to resort to commenting out lines of code until I found the issue.

Turns out as long as I don’t call toString() on a date object I won’t get that issue.  I was logging alot of dates using something like

Log.d(TAG, “date=”+new Date(millis));

If I change that to

Log.d(TAG, “date=”+android.text.format.DateFormat.format(”MM/dd/yyyy h:mmaa z”, millis));

I don’t have the issue.

Most likely the problem would have gone away anyways when I removed log statements.

Comments are closed.