Set Date in a single line

Posted by hibernate on Stack Overflow See other posts from Stack Overflow or by hibernate
Published on 2010-05-20T20:26:31Z Indexed on 2010/05/20 20:30 UTC
Read the original article Hit count: 169

Filed under:
|
|

According to the java API, the constructor Date(year, month, day) is depreciated. I know that I can replace it with the following code:

Calendar myCal = Calendar.getInstance();
myCal.set(Calendar.YEAR, theYear);
myCal.set(Calendar.MONTH, theMonth);
myCal.set(Calendar.DAY_OF_MONTH, theDay);
Date theDate = myCal.getTime();

However, I would like something shorter to replace it with (ideally one-two lines).

Any suggestions?

© Stack Overflow or respective owner

Related posts about java

Related posts about calendar