Example usage for java.util Calendar DAY_OF_MONTH

List of usage examples for java.util Calendar DAY_OF_MONTH

Introduction

In this page you can find the example usage for java.util Calendar DAY_OF_MONTH.

Prototype

int DAY_OF_MONTH

To view the source code for java.util Calendar DAY_OF_MONTH.

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:Main.java

public static Date getDate(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from   w w  w.  j a  v  a  2s .  c om*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static Date addDay(Date date, int days) {
    return add(date, Calendar.DAY_OF_MONTH, days);
}

From source file:Main.java

public static String toYYYYMMDDHHMMSS(Calendar source) {
    if (source == null) {
        return "Can't toYYYYMMDDHHMMSS source null";
    }/*from  w w w  . j  a  v a 2 s  .  com*/
    int YYYY = source.get(Calendar.YEAR);
    int MM = source.get(Calendar.MONTH);
    int DD = source.get(Calendar.DAY_OF_MONTH);
    int HH = source.get(Calendar.HOUR_OF_DAY);
    int mm = source.get(Calendar.MINUTE);
    int SS = source.get(Calendar.SECOND);

    return YYYY + "-" + MM + "-" + DD + " " + HH + ":" + mm + ":" + SS;
}

From source file:Main.java

public static String getYesterdayFormattedTime() {

    Calendar calendar = getCurrentCalendar();
    calendar.add(Calendar.HOUR_OF_DAY, -9);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
    String result = format.format(calendar.getTime());
    String standardName = "";
    if (result.contains("JST")) {
        standardName = "JST";
        result = result.replaceAll(standardName, "+09:00");
    } else if (result.contains("GMT")) {
        standardName = "GMT";
        result = result.replaceAll(standardName, "");
    }/*  ww w .  j  a  v  a2 s .c  o m*/
    return result;
}

From source file:Main.java

public static int getNumberOfDaysInPreviousMonth(Date someDayInCurrentMonth) {
    Calendar lastMonthCal = Calendar.getInstance();
    lastMonthCal.setTime(someDayInCurrentMonth);
    lastMonthCal.add(Calendar.MONTH, -1);
    return lastMonthCal.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

/**
 * Check the schedule has expired or not
 * /*from  ww  w  . java2 s  .  com*/
 * @param endDate
 * @return
 */
public static boolean hasNotExpired(Date endDate) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_MONTH, -1);

    // Check expired date
    return (endDate == null || cal.getTime().before(endDate));
}

From source file:Main.java

private static String formatPeriodDate(int daysPeriod) {
    Calendar now = Calendar.getInstance();
    Calendar period = Calendar.getInstance();
    period.add(Calendar.DAY_OF_MONTH, daysPeriod);
    SimpleDateFormat sdf = new SimpleDateFormat("MMMM", Locale.US);

    if (now.get(Calendar.YEAR) == period.get(Calendar.YEAR)) {
        if (now.get(Calendar.MONTH) == period.get(Calendar.MONTH)) {
            return period.get(Calendar.DAY_OF_MONTH) + "-" + now.get(Calendar.DAY_OF_MONTH) + " "
                    + sdf.format(now.getTime()) + ", " + now.get(Calendar.YEAR);
        }//w ww .  j a v  a 2 s.c o m
        return period.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(period.getTime()) + " - "
                + now.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(now.getTime()) + ", "
                + now.get(Calendar.YEAR);
    }
    return period.get(Calendar.DAY_OF_MONTH) + " " + sdf.format(period.getTime()) + " "
            + period.get(Calendar.YEAR) + " - " + now.get(Calendar.DAY_OF_MONTH) + " "
            + sdf.format(now.getTime()) + " " + now.get(Calendar.YEAR);
}

From source file:Main.java

public static String genererNomFichierInexistant(String directory, String extensionFichier) {
    Calendar c = Calendar.getInstance();
    File aRetourner;/*from w w  w. j  ava2s .  com*/
    if (extensionFichier.equals("")) {
        aRetourner = new File(
                c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_" + c.get(Calendar.YEAR) + "_"
                        + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND));
    } else if (directory.equals("")) {
        aRetourner = new File(c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_"
                + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":"
                + c.get(Calendar.SECOND) + "." + extensionFichier);
    } else {
        aRetourner = new File(directory + "/" + c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.MONTH) + "_"
                + c.get(Calendar.YEAR) + "_" + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":"
                + c.get(Calendar.SECOND) + "." + extensionFichier);
    }

    return aRetourner.getPath();
}

From source file:Main.java

public static boolean isOver18(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    int months = (cal.get(Calendar.YEAR) - year) * 12;
    months += cal.get(Calendar.MONTH) - month;
    int age = months / 12;

    if (age < 18 || (age == 18 && day > cal.get(Calendar.DAY_OF_MONTH))) {
        return false;
    }//from  w ww. j a  va2s  .c  o m

    return true;
}

From source file:Main.java

public static String getTodayYYYYMMDD() {
    Calendar calendar = Calendar.getInstance();
    StringBuffer sbDate = new StringBuffer();
    int nYear, nMonth, nDay;
    nYear = calendar.get(Calendar.YEAR);
    nMonth = calendar.get(Calendar.MONTH) + 1;
    nDay = calendar.get(Calendar.DAY_OF_MONTH);
    sbDate.append(nYear);//from w  w w  .  ja  va  2  s.  c  om
    if (nMonth < 10)
        sbDate.append("0");
    sbDate.append(nMonth);
    if (nDay < 10)
        sbDate.append("0");
    sbDate.append(nDay);

    return sbDate.toString();
}