把Java8 的Date包移植到Android中:ThreeTenABP

jopen 9年前發布 | 23K 次閱讀 Android開發 移動開發 ThreeTenABP

把Java8 的Date包移植到Android中來,主要就是替換joda。Java 8 date api的主要設計者就是joda的創建者,新的API對joda做了不少改進。另外移植過來的包大小比joda小,api數目也少。

Usage

Initialize the timezone information in yourApplication.onCreate()method:

@Override public void onCreate() {
  super.onCreate();
  AndroidThreeTen.init(this);
}

Why JSR-310?

JSR-310 was included in Java 8 as thejava.time.*package. It is a full replacement for the ailingDateandCalendarAPIs in both Java and Android. JSR-310 was backported to Java 6 by its creator, Stephen Colebourne, from which this library is adapted.

Why not use ThreeTenBP?

Similar to the problems with using Joda-Time on Android, the threetenbp uses a JAR resource for loading timezone information. This is an extremely inefficient mechanism on Android.

This library places the timezone information as a standard Android asset and provides a custom loader for parsing it efficiently.

Why not use Joda-Time?

Joda-Time has a very large API which brings with it a very large binary size and large method count. The creator of both JSR-310 and Joda-Time has also said that while Joda-Time isn't broken, it does have design flaws.

If you are using Joda-Time already, there's little reason to switch unless its size or method count is relevant to you. For new projects, however, this library offers the standard APIs in Java 8 as a much smaller package in not only binary size and method count, but also in API size.

Download

compile 'com.jakewharton.threetenabp:threetenabp:1.0.0-SNAPSHOT'

Snapshots of the development version are available in Sonatype'ssnapshotsrepository.

項目主頁:http://www.baiduhome.net/lib/view/home/1436327244114

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!