如何从年,月和日获取Date对象? [英] How to get a Date object from year,month and day?
问题描述
当我使用以下代码时,Date对象错误。
When I used the following code,the Date Object was wrong.
日期date = new Date(day.getYear (),day.getMonth(),day.getDay()); \
任何人都可以告诉我如何获取日期对象从年,月和日的价值?非常感谢。
Can anyone tell me how to get the Date Object From the value of year,month and day?Thanks a lot.
推荐答案
不知道更多我会有猜测,但可能你没有看到那个不建议使用的构造函数的JavaDoc:
Without knowing more I'd have to guess but probably you didn't read the JavaDoc on that deprecated constructor:
year 年份减去1900.
月 0-11之间的月份。
日期在1-31之间。
year the year minus 1900.
month the month between 0-11.
date the day of the month between 1-31.
如你所见,如果你想为今天(2015年8月5日)创建一个日期,你会需要使用新日期(115,7,5);
As you can see, if you want to create a date for today (Aug 5th 2015) you'd need to use new Date (115, 7, 5);
如果您看到该文档,您可以自由猜测为什么这是不推荐的,不应该在任何新的代码中使用。 :)
If you see that documentation you are free to guess why this is deprecated and should not be used in any new code. :)
这篇关于如何从年,月和日获取Date对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!