Java equivalent of .NET DateTime.MinValue, DateTime.Today

后端 未结 6 1217
梦毁少年i
梦毁少年i 2021-01-17 08:19

Is there a Java equivalent of DateTime.MinValue and DateTime.Today in the Java Date class? Or a way of achieving something similar?

I\'ve realised how spoilt you are

6条回答
  •  -上瘾入骨i
    2021-01-17 08:59

    The de-facto Java datetime API is joda-time.

    With it, you can get the current date/time by just constructing new DateTime().

    Similarly, Without it, you can use Calendar.getInstance() or new Date() to obtain the current date/time.

    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.

提交回复
热议问题