Adi Adi - 4 months ago 25
Java Question

How to set Calender to Particular date and time in java

I am using Calender class of java ..Here calender has been set for day of week and time .Now as per my need i want to set it for date of month and time like calender should be set for 10th of month and time time should be 10 a.m..But i am not able to get it ..

Here is my code..

Calendar date = Calendar.getInstance();
date.set(Calendar.HOUR, 10);
date.set(Calendar.MINUTE, 58);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);

Please help me..
Thanks in advance..


If you want set the date of the month, then you could use either of the two, interchangeably.

date.set(Calendar.DAY_OF_MONTH, 10); // Synonym of DATE
date.set(Calendar.DATE, 10); // Synonym of DAY_OF_MONTH