Java Code Examples for java.util.Calendar.PM

The following are Jave code examples for showing how to use PM of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DateTimePicker   File: TimePickerSpinnerDelegate.java   View Source Code Vote up 8 votes
private void updateAmPmControl() {
    if (is24Hour()) {
        if (mAmPmSpinner != null) {
            mAmPmSpinner.setVisibility(View.GONE);
        } else {
            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);
        }
    }
    mDelegator.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
}
 
Example 2
Project: AcopioMX   File: DateUtils.java   View Source Code Vote up 7 votes
public static String formatDte(String date) {
    SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
    try {
        Date dt = sdt.parse(date);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(dt.getTime());
        int y = calendar.get(Calendar.YEAR)-2000;
        int m = calendar.get(Calendar.MONTH)+1;
        int d = calendar.get(Calendar.DAY_OF_MONTH);
        int hr = calendar.get(Calendar.HOUR_OF_DAY);
        int min = calendar.get(Calendar.MINUTE);
        String time = "AM";
        if (calendar.get(Calendar.AM_PM) == Calendar.PM) { time = "PM"; }
        String day  = String.valueOf(d);
        String month = String.valueOf(m);
        String minute = String.valueOf(min);
        if (d < 10) { day  = "0"+day;  }
        if (m < 10) { month = "0"+month; }
        if (min < 10) { minute = "0"+minute; }
        return month+"/"+day+"/"+y+" "+hr+":"+minute+" "+time;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return "";
}
 
Example 3
Project: AndroidUtility   File: AlertDialog.java   View Source Code Vote up 7 votes
@SuppressWarnings("WrongConstant")
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    int hour, min;
    Calendar datetime = Calendar.getInstance();
    String am_pm = "" ;
    datetime.set(Calendar.HOUR_OF_DAY, hourOfDay);
    datetime.set(Calendar.MINUTE, minute);

    if (datetime.get(Calendar.AM_PM) == Calendar.AM)
        am_pm = "AM";
    else if (datetime.get(Calendar.AM_PM) == Calendar.PM)
        am_pm = "PM";
    hourOfDay = hourOfDay > 12 ? hourOfDay - 12 : hourOfDay;
    hour = hourOfDay > 9 ? hourOfDay : hourOfDay;
    min = minute > 9 ? minute : minute;
    timeInterface.setTime(hour, min, am_pm);
}
 
Example 4
Project: Weather-Forecast   File: MainWeatherFrame.java   View Source Code Vote up 6 votes
private void UpdateTimerValue() {
    final Calendar cal = Calendar.getInstance();
    final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    final String timeValue = sdf.format(cal.getTime());
    if (cal.get(Calendar.AM_PM) == Calendar.PM) {
        jLabel20.setText(timeValue + " PM");
    } else {
        jLabel20.setText(timeValue + " AM");
    }
}