概述
int day = Integer.parseInt(request.getParameter("day")); //25
int month = Integer.parseInt(request.getParameter("month")); //12
int year = Integer.parseInt(request.getParameter("year")); // 1988
System.out.println(year);
Calendar c = Calendar.getInstance();
c.set(year, month, day, 0, 0);
b.setDob(c.getTime());
System.out.println(b.getDob());
Output is -
1988
Wed Jan 25 00:00:08 IST 1989
i am passing 25 12 1988 but i get 25 jan 1989 why?
where is the problem ?
here is the Docs for Calendar.set which i followed -
解决方案
Months are zero-based in Calendar. So 12 is interpreted as december + 1 month. Use
c.set(year, month - 1, day, 0, 0);
最后
以上就是清爽墨镜为你收集整理的java 创建一个日期对象,从年,月,日创建java日期对象的全部内容,希望文章能够帮你解决java 创建一个日期对象,从年,月,日创建java日期对象所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复