Creating java date object from year,month,day

前端 未结 6 1060
长情又很酷
长情又很酷 2020-11-27 14:50
int day = Integer.parseInt(request.getParameter(\"day\"));  // 25
int month = Integer.parseInt(request.getParameter(\"month\")); // 12
int year = Integer.parseInt(re         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 15:13

    Java's Calendar representation is not the best, they are working on it for Java 8. I would advise you to use Joda Time or another similar library.

    Here is a quick example using LocalDate from the Joda Time library:

    LocalDate localDate = new LocalDate(year, month, day);
    Date date = localDate.toDate();
    

    Here you can follow a quick start tutorial.

提交回复
热议问题