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 Calendar GetYesterdayLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar GetYesterdayRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

static float getDatePlg() {
    Calendar c = new GregorianCalendar();
    int y = c.get(Calendar.YEAR);
    int m = 1 + c.get(Calendar.MONTH);
    int d = c.get(Calendar.DAY_OF_MONTH);
    return getDatePlg(y, m, d);
}

From source file:Main.java

public static Date getDateTimeFrom(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_MONTH, 0);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.YEAR, 0);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Date ret = calendar.getTime();
    return ret;/*from   www  . j  a v a2 s. c  om*/
}

From source file:Main.java

public static boolean isBefore(Calendar currentCalendar, Calendar max) {
    int currentYear = currentCalendar.get(Calendar.YEAR);
    int currentMonth = currentCalendar.get(Calendar.MONTH);
    int currentDay = currentCalendar.get(Calendar.DAY_OF_MONTH);
    int maxYear = max.get(Calendar.YEAR);
    int maxMonth = max.get(Calendar.MONTH);
    int maxDay = max.get(Calendar.DAY_OF_MONTH);
    Log.i("TAG",/*from w  w  w  .  j a v a  2  s .c o m*/
            (currentYear <= maxYear && currentMonth <= maxMonth && currentDay <= maxDay) + "currentYear"
                    + currentYear + "maxYear" + maxYear + "currentMonth" + currentMonth + "maxMonth" + maxMonth
                    + "currentDay" + currentDay + "maxDay" + maxDay);
    return (currentYear == maxYear)
            ? ((currentMonth == currentMonth) ? (currentDay < maxDay) : (currentMonth < maxMonth))
            : (currentYear < maxYear);
}

From source file:Main.java

public static Calendar tomorrow() {
    Calendar tomorrow = new GregorianCalendar();
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);
    tomorrow.add(Calendar.DAY_OF_MONTH, 1);
    return tomorrow;
}

From source file:Main.java

public static String getCurrentTime() {
    DecimalFormat df = new DecimalFormat("00");
    Calendar c = Calendar.getInstance();
    String currentTime = c.get(Calendar.YEAR)// + "-"
            + df.format((c.get(Calendar.MONTH) + 1)) // + "-"
            + df.format(c.get(Calendar.DAY_OF_MONTH))// + "-"
            + df.format(c.get(Calendar.HOUR_OF_DAY)) // + "-"
            + df.format(c.get(Calendar.MINUTE))// + "-"
            + df.format(c.get(Calendar.SECOND));
    return currentTime;
}

From source file:Main.java

public static int getYears(int year, int month, int day) {

    GregorianCalendar cal = new GregorianCalendar();
    int y, m, d, noofyears;

    y = cal.get(Calendar.YEAR);// current year ,
    m = cal.get(Calendar.MONTH);// current month 
    d = cal.get(Calendar.DAY_OF_MONTH);//current day
    cal.set(year, month, day);// here ur date 
    noofyears = y - cal.get(Calendar.YEAR);
    if ((m < cal.get(Calendar.MONTH))
            || ((m == cal.get(Calendar.MONTH)) && (d < cal.get(Calendar.DAY_OF_MONTH)))) {
        --noofyears;/*from   w  w  w  . j  a  v  a 2 s. c  o  m*/
    }
    try {
        if (noofyears < 0)
            throw new IllegalArgumentException("age < 0");
    } catch (IllegalArgumentException ile) {
        ile.printStackTrace();
    }
    System.out.println(noofyears);
    return noofyears;
}

From source file:Main.java

public static String getNowDataForChart() {
    Calendar calendar = Calendar.getInstance();
    int month = calendar.get(Calendar.MONTH) + 1;
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    return month + "-" + day;
}

From source file:Main.java

public static Date addDays(Date date, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from  w ww .jav  a 2s . co m*/
    cal.add(Calendar.DAY_OF_MONTH, days);
    return cal.getTime();
}