java.util.Date类的参数化构造函数已被弃用。什么是替代品? [英] The parameterized constructors of the java.util.Date class are deprecated. What is the alternative?
问题描述
我可以用什么来替换这个, new Date(2009,12,9)
?
What can I use to replace this, new Date(2009, 12, 9)
?
谢谢为您的帮助。
推荐答案
理想情况下,使用 Joda Time 。这是一个无与伦比的API内置的API。然后,您可以选择 LocalDateTime
和 DateTime
根据您的具体要求(这是一个复杂的区域 - 我不会试图在一两句话中总结, a href =http://joda-time.sourceforge.net/quickstart.html =nofollow noreferrer> docs 做的很好)。
Ideally, use Joda Time instead. It's an infinitely superior API to the built-in one. You'd then want to choose between LocalDateTime
and DateTime
depending on your exact requirements (it's a complicated area - I'm not going to try to summarise in a sentence or two, but the docs do a good job).
如果绝对必要,请使用 java.util .Calendar ,并在需要时将其转换为 Date
。
If absolutely necessary, use a java.util.Calendar and convert that to a Date
when you need to.
这篇关于java.util.Date类的参数化构造函数已被弃用。什么是替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!