Java Day of Month setDayOfMonth(Date d, int date)

Here you can find the source of setDayOfMonth(Date d, int date)

Description

set Day Of Month

License

Open Source License

Declaration

public static Date setDayOfMonth(Date d, int date) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Date setDayOfMonth(Date d, int date) {
        Calendar c = getCalendar();
        c.setTime(d);//  w w  w  .  j  a  v a2  s .com
        c.set(Calendar.DAY_OF_MONTH, date);
        return (c.getTime());
    }

    /**
     * month ranges from 1 to 12 (not 0 to 11)
     */
    private static Calendar getCalendar() {
        return (getCalendar(null, null));
    }

    private static Calendar getCalendar(TimeZone timeZone, Locale locale) {
        if (timeZone == null)
            timeZone = TimeZone.getDefault();

        if (locale == null)
            locale = Locale.getDefault();

        Calendar c = new GregorianCalendar(timeZone, locale);
        return (c);
    }

    public static Date setTime(Date d, long time) {
        d.setTime(time);
        return (d);
    }

    public static long getTime() {
        Date d = new Date();
        return (d.getTime());
    }

    public static long getTime(Date d) {
        return (d.getTime());
    }
}

Related

  1. getWeekOfFirstDayOfMonth(Date date)
  2. getWeekOfLastDayOfMonth(Date date)
  3. isGivenDayOfMonth(java.util.Date date, int dayOfMonth)
  4. isSameDayOfMonth(Date dt1, Date dt2)
  5. newDate(int year, int month, int dayOfMonth)
  6. toDate(final int year, final int month, final int dayOfMonth)