Sep 23

Use the Calendar class to set the day of the month to the first day of the month.


// Create a Calendar instance
// and set it to the date of interest

Calendar cal = Calendar.getInstance();
cal.setTime(date);

// Set the day of the month to the first day of the month

cal.set(Calendar.DAY_OF_MONTH, 
   cal.getActualMinimum(Calendar.DAY_OF_MONTH));

// Extract the Date from the Calendar instance 

Date firstDayOfTheMonth = cal.getTime(); 

written by objects \\ tags: ,


Leave a Reply

You must be logged in to post a comment.