Java Date Start getStartOfMonth(Date dt)

Here you can find the source of getStartOfMonth(Date dt)

Description

Get the start of the month

License

Open Source License

Parameter

Parameter Description
dt a parameter

Declaration

public static Date getStartOfMonth(Date dt) 

Method Source Code

//package com.java2s;
/*//ww  w. ja  v a 2 s. c  o  m
 * Author Stephen Booysen
 *
 * Copyright (c) 2015 Stephen Booysen, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Stephen Booysen. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Stephen Booysen
 *
 * Stephen Booysen MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**
     * Get the start of the month
     * 
     * @param dt
     * @return
     */
    public static Date getStartOfMonth(Date dt) {

        Calendar c = Calendar.getInstance();
        c.setTime(dt);
        c.set(Calendar.DAY_OF_MONTH, 1);

        return c.getTime();
    }

    /**
     * Set the time of the given Date
     *
     * @param date
     * @param hourOfDay
     * @param minute
     * @param second
     * @param ms
     *
     * @return new instance of java.util.Date with the time set
     */
    public static Date setTime(final Date date, final int hourOfDay, final int minute, final int second,
            final int ms) {
        final GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.set(Calendar.HOUR_OF_DAY, hourOfDay);
        gc.set(Calendar.MINUTE, minute);
        gc.set(Calendar.SECOND, second);
        gc.set(Calendar.MILLISECOND, ms);
        return gc.getTime();
    }
}

Related

  1. getStartOfDay(Date date)
  2. getStartOfDay(Date day)
  3. getStartOfDay(Date day)
  4. getStartOfMonth(Date date)
  5. getStartOfMonth(Date dt)
  6. getStartOfQuarter(Date dt)
  7. getStartTimeByManDay(Date serviceStartTime)
  8. getStartTimeOfDate(Date date)
  9. getStartTimeOfDay(Date date)