Date constructor java

前端 未结 6 1718
别那么骄傲
别那么骄傲 2021-01-18 04:49

Hello I am trying to get the current date at java at a Class I created but everything fails. I\'ve seen in many sites e.g. http://www.mkyong.com/java/java-date-and-calenda

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 05:36

    The examples you found are for java.util.Date while you are using java.sql.Date

    • java.sql.Date

      has two constructors

      • Date(long date): Constructs a Date object using the given milliseconds time value.
      • Date(int year, int month, int day): which is deprecated

      and no default Date() constructor.

    • java.util.Date

      among others has a default constructor without arguments

      • Date(): Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

    When importing classes, Eclipse will help you fining possible candidates but always check if the first suggestion is really what you want.

提交回复
热议问题