How to initialize a variable of date type in java?

前端 未结 5 1691
借酒劲吻你
借酒劲吻你 2021-02-20 02:57
import java.util.Date;
Date firstDate; 

I don\'t know how to intialize the firstDate for example for String you say

String line1=\"Fir         


        
5条回答
  •  长发绾君心
    2021-02-20 03:39

    java.util.Date constructor with parameters like new Date(int year, int month, int date, int hrs, int min). is deprecated and preferably do not use it any more. Oracle docs prefers the way over java.util.Calendar. So you can set any date and instantiate Date object through the getTime() method.

    Calendar calendar = Calendar.getInstance();
    calendar.set(2018, 11, 31, 59, 59, 59);
    Date happyNewYearDate = calendar.getTime();
    

    Notice that month number starts from 0

提交回复
热议问题