Example usage for java.util Calendar PM

List of usage examples for java.util Calendar PM

Introduction

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

Prototype

int PM

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

Click Source Link

Document

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

Usage

From source file:com.massivekinetics.ow.ui.views.timepicker.TimePicker.java

private void updateAmPmControl() {
    if (is24HourView()) {
        if (mAmPmSpinner != null) {
            mAmPmSpinner.setVisibility(View.GONE);
        } else {/*from  w  w  w .j a va 2s  . co m*/
            mAmPmButton.setVisibility(View.GONE);
        }
    } else {
        int index = mIsAm ? Calendar.AM : Calendar.PM;
        if (mAmPmSpinner != null) {
            mAmPmSpinner.setValue(index);
            mAmPmSpinner.setVisibility(View.VISIBLE);
        } else {
            mAmPmButton.setText(mAmPmStrings[index]);
            mAmPmButton.setVisibility(View.VISIBLE);
        }
    }
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private void init(Context context) {
    setFocusable(true);// w  w w.  j a  v a 2  s  . c o  m

    // Allow focus in touch mode so that we can do keyboard shortcuts
    // even after we've entered touch mode.
    setFocusableInTouchMode(true);
    setClickable(true);
    setOnCreateContextMenuListener(this);

    mFirstDayOfWeek = Time.MONDAY;

    mCurrentTime = new Time(DayUtils.getTimeZone(context, mTZUpdater));
    long currentTime = System.currentTimeMillis();
    mCurrentTime.set(currentTime);
    mTodayJulianDay = Time.getJulianDay(currentTime, mCurrentTime.gmtoff);

    mEventTextPaint.setTextSize(EVENT_TEXT_FONT_SIZE);
    mEventTextPaint.setTextAlign(Align.LEFT);
    mEventTextPaint.setAntiAlias(true);

    int gridLineColor = 0xff707070;
    Paint p = mSelectionPaint;
    p.setColor(gridLineColor);
    p.setStyle(Style.FILL);
    p.setAntiAlias(false);

    p = mPaint;
    p.setAntiAlias(true);

    // Long day names
    mDayStrsLong = new String[14];

    // Allocate space for 2 weeks worth of weekday names so that we can
    // easily start the week display at any week day.
    mDayStrs = new String[14];

    // Also create an array of 2-letter abbreviations.
    mDayStrs2Letter = new String[14];

    for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
        int index = i - Calendar.SUNDAY;

        mDayStrsLong[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_LONG).toUpperCase();
        mDayStrsLong[index + 7] = mDayStrsLong[index];
        // e.g. Tue for Tuesday
        mDayStrs[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_MEDIUM).toUpperCase();
        mDayStrs[index + 7] = mDayStrs[index];
        // e.g. Tu for Tuesday
        mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORT).toUpperCase();

        // If we don't have 2-letter day strings, fall back to 1-letter.
        if (mDayStrs2Letter[index].equals(mDayStrs[index])) {
            mDayStrs2Letter[index] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORTEST);
        }

        mDayStrs2Letter[index + 7] = mDayStrs2Letter[index];
    }

    // Figure out how much space we need for the 3-letter abbrev names
    // in the worst case.
    p.setTextSize(DATE_HEADER_FONT_SIZE);
    p.setTypeface(mBold);
    String[] dateStrs = { " 28", " 30" };
    mDateStrWidth = computeMaxStringWidth(0, dateStrs, p);
    Time time = new Time();
    time.setJulianDay(mFirstJulianDay);
    String s = SimpleDateFormat.getDateInstance().format(new Date(time.toMillis(false)));
    mDateStrWidthLong = computeMaxStringWidth(0, new String[] { s }, p);
    p.setTextSize(DAY_HEADER_FONT_SIZE);
    mDateStrWidth += computeMaxStringWidth(0, mDayStrs, p);
    mDateStrWidthLong += computeMaxStringWidth(0, mDayStrsLong, p);

    p.setTextSize(HOURS_TEXT_SIZE);
    p.setTypeface(null);
    handleOnResume();

    mAmString = DateUtils.getAMPMString(Calendar.AM).toUpperCase();
    mPmString = DateUtils.getAMPMString(Calendar.PM).toUpperCase();
    String[] ampm = { mAmString, mPmString };
    p.setTextSize(AMPM_TEXT_SIZE);
    mHoursWidth = Math.max(HOURS_MARGIN, computeMaxStringWidth(mHoursWidth, ampm, p) + HOURS_RIGHT_MARGIN);
    mHoursWidth = Math.max(MIN_HOURS_WIDTH, mHoursWidth);

    LayoutInflater inflater;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    Resources.Theme dialogTheme = getResources().newTheme();
    dialogTheme.applyStyle(android.R.style.Theme_Dialog, true);
    TypedArray ta = dialogTheme.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });

    // Catch long clicks for creating a new event
    mBaseDate = new Time(DayUtils.getTimeZone(context, mTZUpdater));
    long millis = System.currentTimeMillis();
    mBaseDate.set(millis);

    mEarliestStartHour = new int[mNumDays];
    mHasAllDayEvent = new boolean[mNumDays];

    // mLines is the array of points used with Canvas.drawLines() in
    // drawGridBackground() and drawAllDayEvents().  Its size depends
    // on the max number of lines that can ever be drawn by any single
    // drawLines() call in either of those methods.
    final int maxGridLines = (24 + 1) // max horizontal lines we might draw
            + (mNumDays + 1); // max vertical lines we might draw
    mLines = new float[maxGridLines * 4];
}

From source file:org.apache.orc.impl.mask.RedactMaskFactory.java

/**
 * Given the requested masking parameters, redact the given time
 * @param millis the original time/*  www.  j a v  a2  s  .  com*/
 * @return the millis after it has been masked
 */
long maskTime(long millis) {
    scratch.setTimeInMillis(millis);
    if (YEAR_REPLACEMENT != UNMASKED_DATE) {
        scratch.set(Calendar.YEAR, YEAR_REPLACEMENT);
    }
    if (MONTH_REPLACEMENT != UNMASKED_DATE) {
        scratch.set(Calendar.MONTH, MONTH_REPLACEMENT - 1);
    }
    if (DATE_REPLACEMENT != UNMASKED_DATE) {
        scratch.set(Calendar.DATE, DATE_REPLACEMENT);
    }
    if (HOUR_REPLACEMENT != UNMASKED_DATE) {
        if (HOUR_REPLACEMENT >= 12) {
            scratch.set(Calendar.HOUR, HOUR_REPLACEMENT - 12);
            scratch.set(Calendar.AM_PM, Calendar.PM);
        } else {
            scratch.set(Calendar.HOUR, HOUR_REPLACEMENT);
            scratch.set(Calendar.AM_PM, Calendar.AM);
        }
    }
    if (MINUTE_REPLACEMENT != UNMASKED_DATE) {
        scratch.set(Calendar.MINUTE, MINUTE_REPLACEMENT);
    }
    if (SECOND_REPLACEMENT != UNMASKED_DATE) {
        scratch.set(Calendar.SECOND, SECOND_REPLACEMENT);
        scratch.set(Calendar.MILLISECOND, 0);
    }
    return scratch.getTimeInMillis();
}

From source file:vn.hss.etrans.yeucauvantai.YeuCauVanTaiPortlet.java

private YeuCauVanTai YeuCauVanTaiFromRequest(PortletRequest request) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    YeuCauVanTaiImpl yeuCauVanTai = new YeuCauVanTaiImpl();
    try {/*w  ww .  ja  v a 2s.  c o m*/
        yeuCauVanTai.setIdYeuCau(Long.valueOf(request.getAttribute("idYeuCau").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
    }
    yeuCauVanTai.setMaYeuCau(request.getAttribute("maYeuCau").toString());
    yeuCauVanTai.setTen(request.getAttribute("ten").toString());
    PortletPreferences prefs = request.getPreferences();
    SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    int ngayNhanHangAno = Integer.valueOf((String) request.getAttribute("ngayNhanHangYear"));
    int ngayNhanHangMes = Integer.valueOf((String) request.getAttribute("ngayNhanHangMonth")) + 1;
    int ngayNhanHangDia = Integer.valueOf((String) request.getAttribute("ngayNhanHangDay"));
    int ngayNhanHangHora = Integer.valueOf((String) request.getAttribute("ngayNhanHangHour"));
    int ngayNhanHangMinuto = Integer.valueOf((String) request.getAttribute("ngayNhanHangMinute"));
    int ngayNhanHangAmPm = Integer.valueOf((String) request.getAttribute("ngayNhanHangAmPm"));

    if (ngayNhanHangAmPm == Calendar.PM) {
        ngayNhanHangHora += 12;
    }

    try {
        SimpleDateFormat formatterDateTime = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        yeuCauVanTai.setNgayNhanHang(formatterDateTime.parse(ngayNhanHangAno + "/" + ngayNhanHangMes + "/"
                + ngayNhanHangDia + " " + ngayNhanHangHora + ":" + ngayNhanHangMinuto));
    } catch (ParseException e) {
        yeuCauVanTai.setNgayNhanHang(new Date());
    }
    int ngayGiaoHangAno = Integer.valueOf((String) request.getAttribute("ngayGiaoHangYear"));
    int ngayGiaoHangMes = Integer.valueOf((String) request.getAttribute("ngayGiaoHangMonth")) + 1;
    int ngayGiaoHangDia = Integer.valueOf((String) request.getAttribute("ngayGiaoHangDay"));
    int ngayGiaoHangHora = Integer.valueOf((String) request.getAttribute("ngayGiaoHangHour"));
    int ngayGiaoHangMinuto = Integer.valueOf((String) request.getAttribute("ngayGiaoHangMinute"));
    int ngayGiaoHangAmPm = Integer.valueOf((String) request.getAttribute("ngayGiaoHangAmPm"));

    if (ngayGiaoHangAmPm == Calendar.PM) {
        ngayGiaoHangHora += 12;
    }

    try {
        SimpleDateFormat formatterDateTime = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        yeuCauVanTai.setNgayGiaoHang(formatterDateTime.parse(ngayGiaoHangAno + "/" + ngayGiaoHangMes + "/"
                + ngayGiaoHangDia + " " + ngayGiaoHangHora + ":" + ngayGiaoHangMinuto));
    } catch (ParseException e) {
        yeuCauVanTai.setNgayGiaoHang(new Date());
    }
    try {
        yeuCauVanTai.setNoiNhan(Long.valueOf(request.getAttribute("noiNhan").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
    }
    try {
        yeuCauVanTai.setNoiGiao(Long.valueOf(request.getAttribute("noiGiao").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
    }
    try {
        yeuCauVanTai.setNoiNhanQH(Long.valueOf(request.getAttribute("noiNhanQH").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
    }
    try {
        yeuCauVanTai.setNoiGiaoQH(Long.valueOf(request.getAttribute("noiGiaoQH").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
    }
    try {
        yeuCauVanTai.setTuGia(Integer.valueOf(request.getAttribute("tuGia").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
        yeuCauVanTai.setTuGia(0);
    }
    try {
        yeuCauVanTai.setDenGia(Integer.valueOf(request.getAttribute("denGia").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
        yeuCauVanTai.setDenGia(0);
    }
    int hanCuoiDauGiaAno = Integer.valueOf((String) request.getAttribute("hanCuoiDauGiaYear"));
    int hanCuoiDauGiaMes = Integer.valueOf((String) request.getAttribute("hanCuoiDauGiaMonth")) + 1;
    int hanCuoiDauGiaDia = Integer.valueOf((String) request.getAttribute("hanCuoiDauGiaDay"));
    int hanCuoiDauGiaHora = Integer.valueOf((String) request.getAttribute("hanCuoiDauGiaHour"));
    int hanCuoiDauGiaMinuto = Integer.valueOf((String) request.getAttribute("hanCuoiDauGiaMinute"));
    int hanCuoiDauGiaAmPm = Integer.valueOf((String) request.getAttribute("hanCuoiDauGiaAmPm"));

    if (hanCuoiDauGiaAmPm == Calendar.PM) {
        hanCuoiDauGiaHora += 12;
    }

    try {
        SimpleDateFormat formatterDateTime = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        yeuCauVanTai.setHanCuoiDauGia(formatterDateTime.parse(hanCuoiDauGiaAno + "/" + hanCuoiDauGiaMes + "/"
                + hanCuoiDauGiaDia + " " + hanCuoiDauGiaHora + ":" + hanCuoiDauGiaMinuto));
    } catch (ParseException e) {
        yeuCauVanTai.setHanCuoiDauGia(new Date());
    }
    try {
        yeuCauVanTai.setIdDauGia(Integer.valueOf(request.getAttribute("idDauGia").toString()));
    } catch (Exception nfe) {
        //Controled en Validator
        yeuCauVanTai.setIdDauGia(0);
    }
    yeuCauVanTai.setMoTa(request.getAttribute("moTa").toString());
    if (request.getAttribute("isDeleted").toString().equalsIgnoreCase("false")) {
        yeuCauVanTai.setIsDeleted(false);
    } else {
        yeuCauVanTai.setIsDeleted(true);
    }
    try {
        yeuCauVanTai.setPrimaryKey(Long.valueOf(request.getAttribute("resourcePrimKey").toString()));
    } catch (NumberFormatException nfe) {
        //Controled en Validator
    }

    yeuCauVanTai.setCompanyId(themeDisplay.getCompanyId());
    yeuCauVanTai.setGroupId(themeDisplay.getScopeGroupId());
    yeuCauVanTai.setUserId(themeDisplay.getUserId());
    return yeuCauVanTai;
}

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 ww  .java  2 s  .  c o m
    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.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;
}