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 int getItemsCounts(int periodType, long date) {
    switch (periodType) {
    case TYPE_DAY:
        return 24;

    case TYPE_WEEK:
        return 7;

    case TYPE_MONTH: {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date);//from w ww .ja  v a2  s. c o  m
        return c.getMaximum(Calendar.DAY_OF_MONTH);
    }

    case TYPE_YEAR: {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date);
        return c.getMaximum(Calendar.MONTH) + 1;
    }
    }

    return 0;
}

From source file:Main.java

public static XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date) {
    if (date == null) {
        return null;
    } else {/*from  w  w  w  . j  ava 2 s . c  om*/
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);

        XMLGregorianCalendar xmlGregorianCalendar = df.newXMLGregorianCalendar();
        xmlGregorianCalendar.setDay(calendar.get(Calendar.DAY_OF_MONTH));
        xmlGregorianCalendar.setMonth(calendar.get(Calendar.MONTH));
        xmlGregorianCalendar.setYear(calendar.get(Calendar.YEAR));

        return xmlGregorianCalendar;
    }
}

From source file:Main.java

public static Date parseData(String text) {
    Calendar calendar = Calendar.getInstance();
    if (text.contains(":")) {
        String[] time = text.split(":");
        int hours = Integer.parseInt(time[0]);
        calendar.set(Calendar.MINUTE, Integer.parseInt(time[1]));
        calendar.set(Calendar.HOUR_OF_DAY, hours);
        return calendar.getTime();
    } else if (text.contains("/")) {
        String[] date = text.split("/");
        if (date.length == 3) {
            calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0]));
            calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1);
            calendar.set(Calendar.YEAR, Integer.parseInt(date[2]));
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            return calendar.getTime();
        } else if (date.length == 2) {
            calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[0]));
            calendar.set(Calendar.MONTH, Integer.parseInt(date[1]) - 1);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            return calendar.getTime();
        }//from  w  w  w .  ja va  2s.com
    }
    return null;
}

From source file:Main.java

/**
 * yyyy-MM-dd HH:mm:ss//from w ww. ja  v a 2 s . c o m
 */
public static String getFormatTime1(Calendar c) {
    if (null == c) {
        return "null";
    }
    DecimalFormat df = new DecimalFormat("00");
    String strCurrTime = 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 strCurrTime;
}

From source file:Main.java

/**
 * returns the string representation of the date X days ago
 * in the appropriate format for the URL
 * @param _numDaysAgo number of days before the current day
 * @return string representation of X days ago
 *//*w ww.  ja  va  2s  .  co m*/
public static String getUrlTimeStringForXDaysAgo(int _numDaysAgo) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.DAY_OF_MONTH, -1 * _numDaysAgo);
    return getUrlTimeString(cal);
}

From source file:Main.java

/**
 * calculate day count//ww  w.  j  ava 2s. com
 * @param startYear start year
 * @param startMonth start month
 * @param startDay start day
 * @param endYear end year
 * @param endMonth end month
 * @param endDay end day
 * @return day count
 */
public static int countDays(int startYear, int startMonth, int startDay, int endYear, int endMonth,
        int endDay) {
    Calendar startC = Calendar.getInstance();
    startC.set(Calendar.YEAR, startYear);
    startC.set(Calendar.MONTH, startMonth - 1);
    startC.set(Calendar.DAY_OF_MONTH, startDay);
    Calendar endC = Calendar.getInstance();
    endC.set(Calendar.YEAR, endYear);
    endC.set(Calendar.MONTH, endMonth - 1);
    endC.set(Calendar.DAY_OF_MONTH, endDay);
    return (int) ((endC.getTimeInMillis() - startC.getTimeInMillis()) / 86400000 + 1);
}

From source file:Main.java

public static int[] splitDate(Calendar calendar) {
    return new int[] { calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY),
            calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND) };
}

From source file:Main.java

public static String getMsgDate(long msg_time) {
    Calendar cl = Calendar.getInstance();
    cl.setTimeInMillis(msg_time); //here your time in miliseconds
    String date = "";

    String[] monthNames = { "January", "February", "March", "April", "May", "June", "July", "August",
            "September", "October", "November", "December" };

    SimpleDateFormat month_date = new SimpleDateFormat("MMM");
    String month_name = monthNames[cl.get(Calendar.MONTH)];

    int day = cl.get(Calendar.DAY_OF_MONTH);
    int year = cl.get(Calendar.YEAR);

    int current_year = Calendar.getInstance().get(Calendar.YEAR);
    if (current_year == year) {
        date = month_name + " " + day;
    } else {/*from  w ww  . ja  v a 2s.  co m*/
        date = month_name + " " + day + ", " + year;
    }

    return date;
}

From source file:Main.java

public static String date2String(Date date, boolean printTime) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);//from w ww .j  a  v a2  s .  co  m
    if (cal.get(Calendar.YEAR) > 10000) {
        return "---";
    }
    return makeTimeString(cal.get(Calendar.DAY_OF_MONTH), 2) + "."
            + makeTimeString(cal.get(Calendar.MONTH) + 1, 2) + "." + makeTimeString(cal.get(Calendar.YEAR), 4)
            + (printTime
                    ? " " + makeTimeString(cal.get(Calendar.HOUR_OF_DAY), 2) + ":"
                            + makeTimeString(cal.get(Calendar.MINUTE), 2) + ":"
                            + makeTimeString(cal.get(Calendar.SECOND), 2)
                    : "");
}

From source file:Main.java

public static boolean isAfterADay(Calendar newCalendar, Calendar oldCalendar) {
    Log.d("TEST", "run isAferDay");
    if (newCalendar.get(Calendar.YEAR) > oldCalendar.get(Calendar.YEAR))
        return true;
    if (newCalendar.get(Calendar.YEAR) == oldCalendar.get(Calendar.YEAR)
            && newCalendar.get(Calendar.MONTH) > oldCalendar.get(Calendar.MONTH))
        return true;
    if (newCalendar.get(Calendar.YEAR) == oldCalendar.get(Calendar.YEAR)
            && newCalendar.get(Calendar.MONTH) == oldCalendar.get(Calendar.MONTH)
            && newCalendar.get(Calendar.DAY_OF_MONTH) > oldCalendar.get(Calendar.DAY_OF_MONTH))
        return true;
    return false;
}