java.util.Date给出错误的日期作为输出.
java.util.Date date = new Date(2014,03,01);
System.out.println("day is" +date.getDay());
Run Code Online (Sandbox Code Playgroud)
输出:天是3
实际上它应该是7
更新:非常感谢我能够获得输出这是我的代码
java.util.Calendar c = java.util.Calendar.getInstance();
c.clear();
c.set(year,month,dd);
System.out.println("day of week "+c.get(java.util.Calendar.DAY_OF_WEEK));
Run Code Online (Sandbox Code Playgroud)
我想你想创建2014年3月1日的日期.但是你的构造函数调用你创建日期3914年4月1日!该API告诉你为什么:
Run Code Online (Sandbox Code Playgroud)A year y is represented by the integer y - 1900. A month is represented by an integer from 0 to 11; 0 is January, 1 is February, and so forth; thus 11 is December. A date (day of month) is represented by an integer from 1 to 31 in the usual manner.
编辑:也不推荐使用此构造函数.请改用日历.
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |