Alternatives to FastDateFormat for efficient date parsing?

后端 未结 6 936
-上瘾入骨i
-上瘾入骨i 2021-02-05 04:29

Well aware of performance and thread issues with SimpleDateFormat, I decided to go with FastDateFormat, until I realized that FastDateFormat

6条回答
  •  星月不相逢
    2021-02-05 05:15

    Found something interesting here of this case in Android: http://andmob.wikidot.com/faq-simpletimeformat

    SimpleDateFormat, the first time you try parsing (or, presumably, formatting) a date, will load in all the timezone data for your locale. This will take 2-3 seconds. It is hoped that this will be fixed in some future edition of Android.

    In the interim, consider using AsyncTask to "warm up" SimpleDateFormat in your process before you need it. Just parse some date in the AsyncTask doInBackground() to get it to load the timezones sometime when it will not impact the user so much. Once initialized in your process, SimpleDateFormat will run quickly until your process is terminated.

提交回复
热议问题