任何企业应用程序都需要处理时间问题。应用程序需要知道当前的时间点和下一个时间点,有时它们还必须计算这两个时间点之间的路径。使用 JDK 完成这项任务将非常痛苦和繁琐。现在来看看 Joda Time,一个面向 Java™ 平台的易于使用的开源时间/日期库。正如您在本文中了解的那样,Joda-Time 轻松化解了处理日期和时间的痛苦和繁琐。
在编写企业应用程序时,常常需要处理日期。并且尤其是在这类项目中 — 保险行业 — 纠正日期计算尤其重要。使用 java.util.Calendar 让人有些不安。如果您也曾使用这个类处理过日期/时间值,那么您就知道它使用起来有多麻烦。因此当接触到 Joda-Time — 面向 Java 应用程序的日期/时间库的替代选择。
Joda-Time 令时间和日期值变得易于管理、操作和理解。事实上,易于使用是 Joda 的主要设计目标。其他目标包括可扩展性、完整的特性集以及对多种日历系统的支持。并且 Joda 与 JDK 是百分之百可互操作的,因此您无需替换所有 Java 代码,只需要替换执行日期/时间计算的那部分代码。
下面是官网给出使用Joda Time的理由:
- Easy to Use. Calendar makes accessing ‘normal’ dates difficult, due to the lack of simple methods. Joda-Time has straightforward field accessors such as getYear() or getDayOfWeek().
使用简单.由于缺乏简单的方法,使得JDK中的Calendar类处理简单日期复杂化,Joda-Time已经简单的属性访问.就像getYear()或者是getDayOfWeek().
- Easy to Extend. The JDK supports multiple calendar systems via subclasses of Calendar. This is clunky, and in practice it is very difficult to write another calendar system. Joda-Time supports multiple calendar systems via a pluggable system based on the Chronology class.
便于扩展.JDK支持Calendar的许多的日历系统的取道。非常幸运的是实际上非常困难的去重写另外的日历系统.Joda-Time基于Chronology类是一个可插拔的支持多种的日历系统系统的取道。
- Comprehensive Feature Set. The library is intended to provide all the functionality that is required for date-time calculations. It already provides out-of-the-box features, such as support for oddball date formats, which are difficult to replicate with the JDK.
具有许多特色设置.这个库本来就是为了设计得提高date-time的计算性功能。它已经提供了out-of-the-box产品特性。比如说支持相对的JDK古怪的日期格式化。
- Up-to-date Time Zone calculations. The time zone implementation is based on the public tz database, which is updated several times a year. New Joda-Time releases incorporate all changes made to this database. Should the changes be needed earlier, manually updating the zone data is easy.
最新的时区计算.时区是基于每年都要修缮服务器时间的公共时间数据库来实现的。新的Joda-Time releases是合并了这个数据库的所有变化.因为必须的修改的更早,手动修改时区数据是非常方便的.
- Calendar support. The library provides 8 calendar systems.
日历系统的支持.这个库支持8种日历系统.
- Easy interoperability. The library internally uses a millisecond instant which is identical to the JDK and similar to other common time representations. This makes interoperability easy, and Joda-Time comes with out-of-the-box JDK interoperability.
交互简单.这个内部的库使用与JDK同一的毫秒和与它一样的时间表现。这就使得它与JDK之间转换简单并且Joda-Time伴随着 out-of-the-box JDK共同使用.
- Better Performance Characteristics. Calendar has strange performance characteristics as it recalculates fields at unexpected moments. Joda-Time does only the minimal calculation for the field that is being accessed.
更好的性能.JDK中Calendar奇怪的性能特性因为它在想不到的时刻重新计算时间.Joda-Time只有极低的重新计算时间的概率.
- Good Test Coverage. Joda-Time has a comprehensive set of developer tests, providing assurance of the library’s quality.
好的测试覆盖.Joda-Time具有广泛的开发者测试来保证这个库的品质.
- Complete Documentation. There is a full User Guide which provides an overview and covers common usage scenarios. The javadoc is extremely detailed and covers the rest of the API.
完整的文档.这里有完整的用户用户指南提供概述与包含一般的使用方法。这个javadoc对于其它的API有非常的详细说明.
- Maturity. The library has been under active development since 2002. It is a mature and reliable code base. A number of related projects are now available.
成熟.这个库自从2002年起处于活跃的使用状态.它是一个成熟可靠的代码库.许多相关的项目都在使用。
- Open Source. Joda-Time is licenced under the business friendly Apache License Version 2.0.
开放源码.Joda-Time得到Apache License Version 2.0的许可。
基于以上原因我们有什么原因不使用Joda-Time呢?
Joda Time 简介
最新推荐文章于 2024-08-16 17:52:04 发布