Java等效于.NET DateTime.MinValue,DateTime.Today [英] Java equivalent of .NET DateTime.MinValue, DateTime.Today
问题描述
Java Date类中是否有Java等效的DateTime.MinValue和DateTime.Today?或者一种实现类似的方式?
Is there a Java equivalent of DateTime.MinValue and DateTime.Today in the Java Date class? Or a way of achieving something similar?
我已经意识到你是用.NET日期时间类来破坏的,我也需要相当于AddDays(),AddMonths( )
I've realised how spoilt you are with the .NET datetime class, I also need the equivalent of AddDays(), AddMonths().
推荐答案
事实上的Java datetime API是 joda-time 。
The de-facto Java datetime API is joda-time.
使用它,您只需构建<$ c $即可获取当前日期/时间c> new DateTime()。
With it, you can get the current date/time by just constructing new DateTime()
.
同样,没有它,你可以使用 Calendar.getInstance()
或新的日期()
获取当前的日期/时间。
Similarly, Without it, you can use Calendar.getInstance()
or new Date()
to obtain the current date/time.
MinValue
可以 Calendar.getInstance(0)
/ new Date(0)
。这将使用默认年表 - 即从1970年1月1日起。由于 MinValue
返回Januar 1,第1年,您可以这样做简单地指定这个日期,使用适当的构造函数的 DateTime
。
MinValue
can be Calendar.getInstance(0)
/ new Date(0)
. This would use the default chronology - i.e. since January 1st, 1970. Since MinValue
returns Januar 1st, year 1, you can do that be simply specifying this date, using the appropriate constructor of DateTime
.
这篇关于Java等效于.NET DateTime.MinValue,DateTime.Today的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!