Java Data Type How to - Create start time for a Month


We would like to know how to create start time for a Month.


/*ww w . j a v  a  2  m*/
import java.util.Calendar;
import java.util.Date;

public class Main {
  public static void main(String[] argv){
    System.out.println(firstTimeOfMonth(new Date()) );
  public static Date firstTimeOfMonth(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
    cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
    return cal.getTime();

The code above generates the following result.