Example usage for java.util Calendar AM_PM

List of usage examples for java.util Calendar AM_PM

Introduction

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

Prototype

int AM_PM

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

Click Source Link

Document

Field number for get and set indicating whether the HOUR is before or after noon.

Usage

From source file:com.lichen.teacher.apps.ActivityLive.java

private void checkStartCountdown() {
    String startTime = "14:35:60";
    SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
    long currentTime = System.currentTimeMillis();

    String currentTimeStr[] = timeFormat.format(currentTime).split(":");
    String startTimeStr[] = startTime.split(":");

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    int apm = calendar.get(Calendar.AM_PM);
    int currentHour = Integer.valueOf(currentTimeStr[0]);
    int currentMinute = Integer.valueOf(currentTimeStr[1]);
    int startHour = Integer.valueOf(startTimeStr[0]);
    int startMinute = Integer.valueOf(startTimeStr[1]);
    if (apm == 1 && currentHour < 12)
        currentHour = currentHour + 12;//from   www.ja  v  a2  s .c  o m
    int countdownHour = startHour - currentHour;
    int countdownMinute = startMinute - currentMinute;
    if (countdownHour == 0 && countdownMinute <= 10) {
        new CountdownThread().start();
        mCheckStartCountdownThreadRunFlag = false;
    }
}

From source file:com.ecofactor.qa.automation.api.ReportsAPITest.java

/**
 * Gets the month params.//  ww w.jav  a2 s.  c  o  m
 * @param month the month
 * @return the month params
 */
private HashMap<String, String> getMonthParams(int month) {

    HashMap<String, String> params = new HashMap<String, String>();
    Calendar start = DateUtil.getUTCCalendar();
    start.set(Calendar.MONTH, month - 1);
    start.set(Calendar.DATE, 1);
    start.set(Calendar.HOUR, 12);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    start.set(Calendar.AM_PM, 0);
    Calendar end = DateUtil.getUTCCalendar();
    end.set(Calendar.MONTH, month - 1);
    end.set(Calendar.DATE, end.getMaximum(Calendar.DATE));
    end.set(Calendar.HOUR, 12);
    end.set(Calendar.MINUTE, 0);
    end.set(Calendar.SECOND, 0);
    start.set(Calendar.AM_PM, 0);
    params.put(ReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(ReportsAPIConfig.END_DATE, DateUtil.format(end, DateUtil.DATE_FMT));
    params.put(ReportsAPIConfig.INTERVAL, "MONTHS");
    return params;
}

From source file:com.ecofactor.qa.automation.api.ReportsAPITest.java

/**
 * Gets the day params.//from   w  w  w .java 2 s.c  o m
 * @return the day params
 */
private HashMap<String, String> getDayParams() {

    HashMap<String, String> params = new HashMap<String, String>();
    Calendar start = DateUtil.getUTCCalendar();
    start.set(Calendar.DAY_OF_MONTH, 1);
    start.set(Calendar.MONTH, 4);
    start.set(Calendar.AM_PM, 0);
    params.put(ReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(ReportsAPIConfig.END_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(ReportsAPIConfig.INTERVAL, "DAYS");
    return params;
}

From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java

/**
 * Gets the month params./*from w w  w .  ja  v  a 2  s .co m*/
 * @param month the month
 * @return the month params
 */
private HashMap<String, String> getMonthParams(int month) {

    HashMap<String, String> params = new HashMap<String, String>();
    Calendar start = DateUtil.getUTCCalendar();
    start.set(Calendar.MONTH, month - 1);
    start.set(Calendar.DATE, 1);
    start.set(Calendar.HOUR, 12);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    start.set(Calendar.AM_PM, 0);
    Calendar end = DateUtil.getUTCCalendar();
    end.set(Calendar.MONTH, month - 1);
    end.set(Calendar.DATE, end.getMaximum(Calendar.DATE));
    end.set(Calendar.HOUR, 12);
    end.set(Calendar.MINUTE, 0);
    end.set(Calendar.SECOND, 0);
    end.set(Calendar.AM_PM, 0);
    params.put(HttpsReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(HttpsReportsAPIConfig.END_DATE, DateUtil.format(end, DateUtil.DATE_FMT));
    params.put(HttpsReportsAPIConfig.INTERVAL, "MONTHS");
    return params;
}

From source file:com.appybite.customer.AllowedHotels.java

protected void Update() {
    c = Calendar.getInstance();//  ww w . j  av  a 2s.com
    curMillis = c.getTime();
    curYear = c.get(Calendar.YEAR);
    curMonth = c.get(Calendar.MONTH) + 1;
    curDay = c.get(Calendar.DAY_OF_MONTH);
    curHour = c.get(Calendar.HOUR_OF_DAY);
    curNoon = c.get(Calendar.AM_PM);
    if (curNoon == 0) {
        noon = "AM";
    } else {
        noon = "PM";
        curHour -= 12;
    }
    curMinute = c.get(Calendar.MINUTE);
    curSecond = c.get(Calendar.SECOND);

    Runnable updater = new Runnable() {
        public void run() {
            tvTime.setText(String.format("%02d:%02d", curHour, curMinute));
        }
    };
    handler.post(updater);
}

From source file:com.ecofactor.qa.automation.api.ReportsAPITest.java

/**
 * Gets the hour params./* w  ww .j a v a 2  s.co m*/
 * @return the hour params
 */
private HashMap<String, String> getHourParams() {

    HashMap<String, String> params = new HashMap<String, String>();
    Calendar start = DateUtil.getUTCCalendar();
    start.set(Calendar.DAY_OF_MONTH, 25);
    start.set(Calendar.MONTH, 4);
    start.set(Calendar.HOUR, 12);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    start.set(Calendar.AM_PM, 0);
    params.put(ReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(ReportsAPIConfig.END_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(ReportsAPIConfig.INTERVAL, "HOURS");
    return params;
}

From source file:com.ecofactor.qa.automation.api.HttpsReportsAPITest.java

/**
 * Gets the hour params./*www .  j  ava2  s.c  om*/
 * @return the hour params
 */
private HashMap<String, String> getHourParams() {

    HashMap<String, String> params = new HashMap<String, String>();
    Calendar start = DateUtil.getUTCCalendar();
    start.set(Calendar.DAY_OF_MONTH, 25);
    start.set(Calendar.MONTH, 4);
    start.set(Calendar.HOUR, 12);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    start.set(Calendar.AM_PM, 0);
    params.put(HttpsReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(HttpsReportsAPIConfig.END_DATE, DateUtil.format(start, DateUtil.DATE_FMT));
    params.put(HttpsReportsAPIConfig.INTERVAL, "HOURS");
    return params;
}

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:com.xunlei.util.DateUtils.java

/**
 * <p>/*  w w w.j  av a  2s. c  om*/
 * Internal calculation method.
 * </p>
 * 
 * @param val the calendar
 * @param field the field constant
 * @param modType type to truncate, round or ceiling
 * @throws ArithmeticException if the year is over 280 million
 */
static void modify(Calendar val, int field, int modType) {
    if (val.get(Calendar.YEAR) > 280000000) {
        throw new ArithmeticException("Calendar value too large for accurate calculations");
    }

    if (field == Calendar.MILLISECOND) {
        return;
    }

    // ----------------- Fix for LANG-59 ---------------------- START ---------------
    // see http://issues.apache.org/jira/browse/LANG-59
    //
    // Manually truncate milliseconds, seconds and minutes, rather than using
    // Calendar methods.

    Date date = val.getTime();
    long time = date.getTime();
    boolean done = false;

    // truncate milliseconds
    int millisecs = val.get(Calendar.MILLISECOND);
    if (MODIFY_TRUNCATE == modType || millisecs < 500) {
        time = time - millisecs;
    }
    if (field == Calendar.SECOND) {
        done = true;
    }

    // truncate seconds
    int seconds = val.get(Calendar.SECOND);
    if (!done && (MODIFY_TRUNCATE == modType || seconds < 30)) {
        time = time - (seconds * 1000L);
    }
    if (field == Calendar.MINUTE) {
        done = true;
    }

    // truncate minutes
    int minutes = val.get(Calendar.MINUTE);
    if (!done && (MODIFY_TRUNCATE == modType || minutes < 30)) {
        time = time - (minutes * 60000L);
    }

    // reset time
    if (date.getTime() != time) {
        date.setTime(time);
        val.setTime(date);
    }
    // ----------------- Fix for LANG-59 ----------------------- END ----------------

    boolean roundUp = false;
    for (int i = 0; i < fields.length; i++) {
        for (int j = 0; j < fields[i].length; j++) {
            if (fields[i][j] == field) {
                // This is our field... we stop looping
                if (modType == MODIFY_CEILING || (modType == MODIFY_ROUND && roundUp)) {
                    if (field == DateUtils.SEMI_MONTH) {
                        // This is a special case that's hard to generalize
                        // If the date is 1, we round up to 16, otherwise
                        // we subtract 15 days and add 1 month
                        if (val.get(Calendar.DATE) == 1) {
                            val.add(Calendar.DATE, 15);
                        } else {
                            val.add(Calendar.DATE, -15);
                            val.add(Calendar.MONTH, 1);
                        }
                        // ----------------- Fix for LANG-440 ---------------------- START ---------------
                    } else if (field == Calendar.AM_PM) {
                        // This is a special case
                        // If the time is 0, we round up to 12, otherwise
                        // we subtract 12 hours and add 1 day
                        if (val.get(Calendar.HOUR_OF_DAY) == 0) {
                            val.add(Calendar.HOUR_OF_DAY, 12);
                        } else {
                            val.add(Calendar.HOUR_OF_DAY, -12);
                            val.add(Calendar.DATE, 1);
                        }
                        // ----------------- Fix for LANG-440 ---------------------- END ---------------
                    } else {
                        // We need at add one to this field since the
                        // last number causes us to round up
                        val.add(fields[i][0], 1);
                    }
                }
                return;
            }
        }
        // We have various fields that are not easy roundings
        int offset = 0;
        boolean offsetSet = false;
        // These are special types of fields that require different rounding rules
        switch (field) {
        case DateUtils.SEMI_MONTH:
            if (fields[i][0] == Calendar.DATE) {
                // If we're going to drop the DATE field's value,
                // we want to do this our own way.
                // We need to subtrace 1 since the date has a minimum of 1
                offset = val.get(Calendar.DATE) - 1;
                // If we're above 15 days adjustment, that means we're in the
                // bottom half of the month and should stay accordingly.
                if (offset >= 15) {
                    offset -= 15;
                }
                // Record whether we're in the top or bottom half of that range
                roundUp = offset > 7;
                offsetSet = true;
            }
            break;
        case Calendar.AM_PM:
            if (fields[i][0] == Calendar.HOUR_OF_DAY) {
                // If we're going to drop the HOUR field's value,
                // we want to do this our own way.
                offset = val.get(Calendar.HOUR_OF_DAY);
                if (offset >= 12) {
                    offset -= 12;
                }
                roundUp = offset >= 6;
                offsetSet = true;
            }
            break;
        }
        if (!offsetSet) {
            int min = val.getActualMinimum(fields[i][0]);
            int max = val.getActualMaximum(fields[i][0]);
            // Calculate the offset from the minimum allowed value
            offset = val.get(fields[i][0]) - min;
            // Set roundUp if this is more than half way between the minimum and maximum
            roundUp = offset > ((max - min) / 2);
        }
        // We need to remove this field
        if (offset != 0) {
            val.set(fields[i][0], val.get(fields[i][0]) - offset);
        }
    }
    throw new IllegalArgumentException("The field " + field + " is not supported");

}

From source file:saphion.services.ForegroundService.java

public String setNotText(String subtext, String mainText, int choice) {
    switch (choice) {
    case 0://w  w  w.  java  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;

}