java.util.Date和Joda Time API之间的差异 [英] Differences between java.util.Date and Joda Time APIs

查看:93
本文介绍了java.util.Date和Joda Time API之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我应该使用Java日期和时间类,还是和Joda Time等第三方库一起去吗? a>

Possible Duplicate:
Should I use Java date and time classes or go with a 3rd party library like Joda Time?

我可以使用一些关于什么时候值得使用Joda Time而不是基本的java .util.Date类。有什么好处? Joda时间可以让你做任何你不能使用Date类的任何事情,还是更容易使用或什么?

I could use some guidance about when it's worth using Joda Time rather than the basic java.util.Date class. What are the benefits? Does Joda Time let you do anything you can't do with the Date class, or is it just easier to work with or what?

另外,我看到有冲突关于Joda Time是否是标准API的一部分的信息。是否标准?

Also, I've seen conflicting info about whether Joda Time is part of the standard API. Is it standard or not?

推荐答案

Java的标准日期和时间类(主要是 java.util.Date java.util.Calendar )的功能有限,并且有一些设计问题。事实上,许多 java.util.Date 的构造函数和方法已被弃用,这是一个迹象。

Java's standard date and time classes (mainly java.util.Date and java.util.Calendar) have limited functionality and have a number of design problems. The fact that many of the constructors and methods of java.util.Date are deprecated is one indication of this.

Joda Time比Java标准库中可用的API有更好的思考。有或没有时区的时间戳类,有仅持有一个日期(年,月,日)或仅一天中的时间段,类别为期间,持续时间和间隔的类,它支持ISO 8601格式(这是标准格式在XML文档中)等等。

Joda Time has a much better thought out API than what's available in Java's standard library. There are classes for timestamps with or without a timezone, classes for holding only a date (year, month, day) or only a time of day, classes for periods, durations and intervals, it supports the ISO 8601 format (which is the standard format in XML documents) and much more.

我将使用Joda Time作为任何项目中的标准日期和时间库 - 实际上没有理由使用 java.util.Date java.util.Calendar

I'd use Joda Time as my standard date and time library in any project - there really is no reason to use java.util.Date and java.util.Calendar.

请注意,在将来的Java版本中,最有可能包含一个新的日期和时间API将会与Joda Time目前可用的内容类似;请参阅 Project ThreeTen

Note that in a future release of Java, a new date and time API will most likely be included that's going to look a lot like what's currently available in Joda Time; see Project ThreeTen.

还可以在Joda时间的主页上查看为什么选择Joda时间?项目。

Also see Why Joda Time? on the home page of the Joda Time project.


此外,我看到有关Joda Time是否是标准API的一部分的冲突信息。是不是标准?

Also, I've seen conflicting info about whether Joda Time is part of the standard API. Is it standard or not?

不,它不是标准API

更新(从评论中复制) :

Java 8现在已经出现,它有一个新的日期和时间API,类似于Joda Time(参见java.time)。如果您使用Java 8,请使用新的日期&时间API。

Java 8 is out now, and it has a new date and time API which is similar to Joda Time (see the package java.time). If you're using Java 8, then please use the new date & time API.

这篇关于java.util.Date和Joda Time API之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆