把Java8 的Date包移植到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.