Example usage for java.util Calendar AM

List of usage examples for java.util Calendar AM

Introduction

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

Prototype

int AM

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

Click Source Link

Document

Value of the #AM_PM field indicating the period of the day from midnight to just before noon.

Usage

From source file:com.l2jfree.gameserver.model.olympiad.Olympiad.java

protected void setNewOlympiadEnd() {
    SystemMessage sm = new SystemMessage(SystemMessageId.OLYMPIAD_PERIOD_S1_HAS_STARTED);
    sm.addNumber(_currentCycle);//from   w w w.  j  a  v  a2s  .c  o m

    Announcements.getInstance().announceToAll(sm);

    Calendar currentTime = Calendar.getInstance();
    currentTime.add(Calendar.MONTH, 1);
    currentTime.set(Calendar.DAY_OF_MONTH, 1);
    currentTime.set(Calendar.AM_PM, Calendar.AM);
    currentTime.set(Calendar.HOUR, 12);
    currentTime.set(Calendar.MINUTE, 0);
    currentTime.set(Calendar.SECOND, 0);
    _olympiadEnd = currentTime.getTimeInMillis();

    Calendar nextChange = Calendar.getInstance();
    _nextWeeklyChange = nextChange.getTimeInMillis() + WEEKLY_PERIOD;
    scheduleWeeklyChange();
}

From source file:org.openbravo.service.json.JsonToDataConverter.java

/**
 * The json conversion looses precision in milliseconds and seconds. This comparison method only
 * compares the other parts of the date object. Depending if a date or a date time is set.
 * //  w  ww.  j  a v  a  2 s .com
 * @param d1
 *          the first date to compare
 * @param d2
 *          the second date to compare
 * @param isDatetime
 *          is it a datetime
 * @return true if d1 and d2 have equal values for year, month and day and for date time also same
 *         values for hour, minutes and seconds.
 */
protected boolean areDatesEqual(Date d1, Date d2, boolean isDatetime, boolean isTime) {
    final Calendar c1 = Calendar.getInstance();
    c1.setTime(d1);
    final Calendar c2 = Calendar.getInstance();
    c2.setTime(d2);
    if (isTime) {
        c2.set(Calendar.MILLISECOND, 0);
        c1.set(Calendar.MILLISECOND, 0);
    } else if (isDatetime) {
        c2.set(Calendar.MILLISECOND, 0);
        c1.set(Calendar.MILLISECOND, 0);
    } else {
        c2.set(Calendar.MILLISECOND, 0);
        c1.set(Calendar.MILLISECOND, 0);
        c2.set(Calendar.SECOND, 0);
        c1.set(Calendar.SECOND, 0);
        c2.set(Calendar.MINUTE, 0);
        c1.set(Calendar.MINUTE, 0);
        c2.set(Calendar.HOUR, 0);
        c1.set(Calendar.HOUR, 0);
        c1.set(Calendar.AM_PM, Calendar.AM);
        c2.set(Calendar.AM_PM, Calendar.AM);
    }
    return c2.getTimeInMillis() == c1.getTimeInMillis();
}

From source file:com.wso2telco.core.dbutils.DbService.java

public SpendLimitDAO getGroupTotalDayAmount(String groupName, String operator, String msisdn)
        throws DBUtilException {

    Connection con = null;//from  w w  w.j a v  a  2 s  .c  om
    PreparedStatement ps = null;
    ResultSet rs = null;
    SpendLimitDAO spendLimitDAO = null;

    try {
        con = DbUtils.getDBConnection();

        Calendar calendarFrom = Calendar.getInstance();
        calendarFrom.set(Calendar.AM_PM, Calendar.AM);
        calendarFrom.set(Calendar.HOUR, 00);
        calendarFrom.set(Calendar.MINUTE, 00);
        calendarFrom.set(Calendar.SECOND, 00);
        calendarFrom.set(Calendar.MILLISECOND, 00);

        Calendar calendarTo = Calendar.getInstance();
        calendarTo.set(Calendar.AM_PM, Calendar.PM);
        calendarTo.set(Calendar.HOUR, 11);
        calendarTo.set(Calendar.MINUTE, 59);
        calendarTo.set(Calendar.SECOND, 59);
        calendarTo.set(Calendar.MILLISECOND, 999);

        String sql = "SELECT SUM(amount) AS amount " + "FROM spendlimitdata  "
                + "where effectiveTime between ? and ? " + "and groupName=? " + "and operatorId=? "
                + "and msisdn=? " + "group by groupName, operatorId, msisdn";

        ps = con.prepareStatement(sql);

        ps.setLong(1, calendarFrom.getTimeInMillis());
        ps.setLong(2, calendarTo.getTimeInMillis());
        ps.setString(3, groupName);
        ps.setString(4, operator);
        ps.setString(5, msisdn);

        rs = ps.executeQuery();

        if (rs.next()) {
            spendLimitDAO = new SpendLimitDAO();
            spendLimitDAO.setAmount(rs.getDouble("amount"));
        }
    } catch (Exception e) {
        DbUtils.handleException("Error while checking Operator Spend Limit. ", e);
    } finally {
        DbUtils.closeAllConnections(ps, con, rs);
    }
    return spendLimitDAO;
}

From source file:com.mb.framework.util.DateTimeUtil.java

/**
 * This method is used for checking the target date is in AM
 * /*from   www .  ja  v a 2  s.c o  m*/
 * @param date
 * @return
 */
public static boolean isAM(Date date) {
    boolean isAM = false;
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    if (Calendar.AM == calendar.get(Calendar.AM_PM))
        isAM = true;

    return isAM;
}

From source file:DateUtil.java

/**
 * Sets the date/time of the Calendar object to the beginning of the Period by
 * setting all fields smaller than the specified period to the minimum value.
 * //from   w  w w .j a  va2  s.c om
 * @param c
 *          The calendar to set.
 * @param p
 *          The DateUtil.Period to set.
 */
public static void setToPeriodStart(Calendar c, Period p) {
    switch (p) {
    case YEAR:
        c.set(Calendar.MONTH, 0);
    case MONTH:
        c.set(Calendar.DAY_OF_MONTH, 1);
    case DAY:
        c.set(Calendar.HOUR_OF_DAY, 0);
    case HOUR:
        c.set(Calendar.MINUTE, 0);
    case MINUTE:
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case WEEK:
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case AMPM:
        if (c.get(Calendar.AM_PM) == Calendar.AM)
            c.set(Calendar.HOUR_OF_DAY, 0);
        else
            c.set(Calendar.HOUR_OF_DAY, 12);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case QUARTER:
        int month = c.get(Calendar.MONTH);
        if (month >= 9)
            c.set(Calendar.MONTH, 9);
        else if (month >= 9)
            c.set(Calendar.MONTH, 6);
        else if (month >= 9)
            c.set(Calendar.MONTH, 3);
        else
            c.set(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, 0);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    }
    return;
}

From source file:com.tr4android.support.extension.picker.time.AppCompatTimePickerDelegate.java

public static String[] getAmPmStrings(Context context) {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat formatter = new SimpleDateFormat("a", context.getResources().getConfiguration().locale);

    String[] result = new String[2];
    calendar.set(Calendar.AM_PM, Calendar.AM);
    result[0] = formatter.format(calendar.getTime());
    calendar.set(Calendar.AM_PM, Calendar.PM);
    result[1] = formatter.format(calendar.getTime());
    return result;
}

From source file:saphion.services.ForegroundService.java

public String setNotText(String subtext, String mainText, int choice) {
    switch (choice) {
    case 0:/*ww w  . j  a  v  a 2 s.  c om*/
        return level + "% remaining";
    case 1:
        return "Temperature: " + temperature;
    case 2:
        return health + ", " + "Temperature: " + temperature;
    case 3:
        return subtext;
    case 4:
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(System.currentTimeMillis() + (reqTime * 1000)));
        String day1 = "";
        switch (cal.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY:
            day1 = "Monday";
            break;
        case Calendar.TUESDAY:
            day1 = "Tuesday";
            break;
        case Calendar.WEDNESDAY:
            day1 = "Wednesday";
            break;
        case Calendar.THURSDAY:
            day1 = "Thursday";
            break;
        case Calendar.FRIDAY:
            day1 = "Friday";
            break;
        case Calendar.SATURDAY:
            day1 = "Saturday";
            break;
        case Calendar.SUNDAY:
            day1 = "Sunday";
            break;
        }
        String str = "";
        if (isconnected) {
            str = "Full Charge at ";
        } else {
            str = "Empty at ";
        }
        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
            return str + ((cal.get(Calendar.HOUR) == 0) ? 12 : cal.get(Calendar.HOUR)) + ":"
                    + ((cal.get(Calendar.MINUTE) + "").length() == 1 ? ("0" + cal.get(Calendar.MINUTE))
                            : cal.get(Calendar.MINUTE))
                    + (cal.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM");
        } else {
            int d = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) + 1;
            if (d == 8)
                d = 1;
            if (cal.get(Calendar.DAY_OF_WEEK) == d)
                day1 = "Tomorrow";
            return str + ((cal.get(Calendar.HOUR) == 0) ? 12 : cal.get(Calendar.HOUR)) + ":"
                    + ((cal.get(Calendar.MINUTE) + "").length() == 1 ? ("0" + cal.get(Calendar.MINUTE))
                            : cal.get(Calendar.MINUTE))
                    + (cal.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM") + ", " + day1;
        }
    case 5:
        Date mydate = TimeFuncs
                .GetItemDate(mPref.getString(PreferenceHelper.LAST_CHARGED, TimeFuncs.getCurrentTimeStamp()));
        Calendar c = Calendar.getInstance();
        c.setTime(mydate);
        String day = "";
        switch (c.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY:
            day = "Monday";
            break;
        case Calendar.TUESDAY:
            day = "Tuesday";
            break;
        case Calendar.WEDNESDAY:
            day = "Wednesday";
            break;
        case Calendar.THURSDAY:
            day = "Thursday";
            break;
        case Calendar.FRIDAY:
            day = "Friday";
            break;
        case Calendar.SATURDAY:
            day = "Saturday";
            break;
        case Calendar.SUNDAY:
            day = "Sunday";
            break;
        }

        if (c.get(Calendar.DAY_OF_WEEK) == Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
            if (isconnected)
                return "Plugged at " + ((c.get(Calendar.HOUR) == 0) ? 12 : c.get(Calendar.HOUR)) + ":"
                        + ((c.get(Calendar.MINUTE) + "").length() == 1 ? ("0" + c.get(Calendar.MINUTE))
                                : c.get(Calendar.MINUTE))
                        + (c.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM");
            else
                return "Unplugged at " + ((c.get(Calendar.HOUR) == 0) ? 12 : c.get(Calendar.HOUR)) + ":"
                        + ((c.get(Calendar.MINUTE) + "").length() == 1 ? ("0" + c.get(Calendar.MINUTE))
                                : c.get(Calendar.MINUTE))
                        + (c.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM");
        } else {
            int d = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1;
            if (d == 0)
                d = 7;
            if (c.get(Calendar.DAY_OF_WEEK) == d)
                day = "Yesterday";
            if (isconnected)
                return "Plugged at " + ((c.get(Calendar.HOUR) == 0) ? 12 : c.get(Calendar.HOUR)) + ":"
                        + ((c.get(Calendar.MINUTE) + "").length() == 1 ? ("0" + c.get(Calendar.MINUTE))
                                : c.get(Calendar.MINUTE))
                        + (c.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM") + ", " + day;
            else
                return "Unplugged at " + ((c.get(Calendar.HOUR) == 0) ? 12 : c.get(Calendar.HOUR)) + ":"
                        + ((c.get(Calendar.MINUTE) + "").length() == 1 ? ("0" + c.get(Calendar.MINUTE))
                                : c.get(Calendar.MINUTE))
                        + (c.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM") + ", " + day;
        }

    case 6:
        return mainText;
    }
    return mainText;

}

From source file:org.kuali.kfs.module.purap.document.service.impl.PurchaseOrderServiceImpl.java

/**
 * Creates and returns a Calendar object of today minus three months.
 *
 * @return Calendar object of today minus three months.
 *///from  w  ww  .j a  v  a 2  s.  co  m
protected Calendar getTodayMinusThreeMonths() {
    Calendar todayMinusThreeMonths = Calendar.getInstance(); // Set to today.
    todayMinusThreeMonths.add(Calendar.MONTH, -3); // Back up 3 months.
    todayMinusThreeMonths.set(Calendar.HOUR, 12);
    todayMinusThreeMonths.set(Calendar.MINUTE, 0);
    todayMinusThreeMonths.set(Calendar.SECOND, 0);
    todayMinusThreeMonths.set(Calendar.MILLISECOND, 0);
    todayMinusThreeMonths.set(Calendar.AM_PM, Calendar.AM);
    return todayMinusThreeMonths;
}