Java Code Examples for java.util.Calendar#PM

The following examples show how to use java.util.Calendar#PM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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
Source File: TimePickerSpinnerDelegate.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
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 3
Source File: TimePickerSpinnerDelegate.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
private void updateAmPmControl() {
    if (is24HourView()) {
        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 4
Source File: TimePicker.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
private void updateAmPmControl() {
    if (is24HourView()) {
        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);
        }
    }
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
}
 
Example 5
Source File: GlobalGUIRoutines.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
@SuppressLint("SimpleDateFormat")
static String timeDateStringFromTimestamp(Context applicationContext, long timestamp){
    String timeDate;
    String androidDateTime=android.text.format.DateFormat.getDateFormat(applicationContext).format(new Date(timestamp))+" "+
            android.text.format.DateFormat.getTimeFormat(applicationContext).format(new Date(timestamp));
    String javaDateTime = DateFormat.getDateTimeInstance().format(new Date(timestamp));
    String AmPm="";
    if(!Character.isDigit(androidDateTime.charAt(androidDateTime.length()-1))) {
        if(androidDateTime.contains(new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM])){
            AmPm=" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM];
        }else{
            AmPm=" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.PM];
        }
        androidDateTime=androidDateTime.replace(AmPm, "");
    }
    if(!Character.isDigit(javaDateTime.charAt(javaDateTime.length()-1))){
        javaDateTime=javaDateTime.replace(" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM], "");
        javaDateTime=javaDateTime.replace(" "+new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.PM], "");
    }
    javaDateTime=javaDateTime.substring(javaDateTime.length()-3);
    timeDate=androidDateTime.concat(javaDateTime);
    return timeDate.concat(AmPm);
}
 
Example 6
Source File: SimpleDateFormat.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse an AM/PM marker. The source marker can be the marker name as
 * defined in DateFormatSymbols, or the first character of the marker name.
 * 
 * @param month as a string.
 * @param offset the offset of original timestamp where marker started, for
 *            error reporting.
 * @return Calendar.AM or Calendar.PM
 * @see DateFormatSymbols
 * @throws ParseException if the source could not be parsed.
 */
int parseAmPmMarker(String source, int ofs) throws ParseException {
	String markers[] = getDateFormatSymbols().getAmPmStrings();
	for (int i = 0; i < markers.length; i++) {
		if (markers[i].equalsIgnoreCase(source)) {
			return i;
		}
	}
	char ch = source.charAt(0);
	if (ch == markers[0].charAt(0)) {
		return Calendar.AM;
	}
	if (ch == markers[1].charAt(0)) {
		return Calendar.PM;
	}
	return throwInvalid("am/pm marker", ofs);
}
 
Example 7
Source File: SimpleDateFormat.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse an AM/PM marker. The source marker can be the marker name as
 * defined in DateFormatSymbols, or the first character of the marker name.
 * 
 * @param month as a string.
 * @param offset the offset of original timestamp where marker started, for
 *            error reporting.
 * @return Calendar.AM or Calendar.PM
 * @see DateFormatSymbols
 * @throws ParseException if the source could not be parsed.
 */
int parseAmPmMarker(String source, int ofs) throws ParseException {
	String markers[] = getDateFormatSymbols().getAmPmStrings();
	for (int i = 0; i < markers.length; i++) {
		if (markers[i].equalsIgnoreCase(source)) {
			return i;
		}
	}
	char ch = source.charAt(0);
	if (ch == markers[0].charAt(0)) {
		return Calendar.AM;
	}
	if (ch == markers[1].charAt(0)) {
		return Calendar.PM;
	}
	return throwInvalid("am/pm marker", ofs);
}
 
Example 8
Source File: SimpleDateFormat.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse an AM/PM marker. The source marker can be the marker name as
 * defined in DateFormatSymbols, or the first character of the marker name.
 * 
 * @param month as a string.
 * @param offset the offset of original timestamp where marker started, for
 *            error reporting.
 * @return Calendar.AM or Calendar.PM
 * @see DateFormatSymbols
 * @throws ParseException if the source could not be parsed.
 */
int parseAmPmMarker(String source, int ofs) throws ParseException {
	String markers[] = getDateFormatSymbols().getAmPmStrings();
	for (int i = 0; i < markers.length; i++) {
		if (markers[i].equalsIgnoreCase(source)) {
			return i;
		}
	}
	char ch = source.charAt(0);
	if (ch == markers[0].charAt(0)) {
		return Calendar.AM;
	}
	if (ch == markers[1].charAt(0)) {
		return Calendar.PM;
	}
	return throwInvalid("am/pm marker", ofs);
}
 
Example 9
Source File: BindingAdapters.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@BindingAdapter("bindDate")
public static void bindDate(@NonNull TextView textView, long timestamp) {
    String androidDateTime = android.text.format.DateFormat.getDateFormat(textView.getContext()).format(new Date(timestamp)) + " " +
            android.text.format.DateFormat.getTimeFormat(textView.getContext()).format(new Date(timestamp));
    String AmPm = "";
    if(!Character.isDigit(androidDateTime.charAt(androidDateTime.length()-1))) {
        if(androidDateTime.contains(new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM])){
            AmPm = " " + new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.AM];
        }else{
            AmPm = " " + new SimpleDateFormat().getDateFormatSymbols().getAmPmStrings()[Calendar.PM];
        }
        androidDateTime=androidDateTime.replace(AmPm, "");
    }
    textView.setText(androidDateTime.concat(AmPm));
}
 
Example 10
Source File: MainWeatherFrame.java    From Weather-Forecast with Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example 11
Source File: CacheUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * To save the current time doing caching or merging
 * 
 * @param folder
 */
public static void saveCurrentTime( String folder ) throws DataException
{
	try
	{
		FileOutputStream fos;

		fos = FileSecurity.createFileOutputStream( new File( folder + PATH_SEP + TIME_DATA ) );

		ObjectOutputStream oos = ObjectSecurity.createObjectOutputStream( fos );

		Calendar calendar = Calendar.getInstance( );

		StringBuffer buffer = new StringBuffer( );

		buffer.append( populate2DigitString( calendar.get( Calendar.YEAR ) ) );
		buffer.append( populate2DigitString( calendar.get( Calendar.MONTH ) + 1 ) );
		buffer.append( populate2DigitString( calendar.get( Calendar.DATE ) ) );
		if ( calendar.get( Calendar.AM_PM ) == Calendar.PM )
			buffer.append( populate2DigitString( calendar.get( Calendar.HOUR ) + 12 ) );
		buffer.append( populate2DigitString( calendar.get( Calendar.MINUTE ) ) );
		buffer.append( populate2DigitString( calendar.get( Calendar.SECOND ) ) );

		oos.writeObject( buffer.toString( ) );

		fos.close( );
		oos.close( );
	}
	catch ( IOException e )
	{
		throw new DataException( e.getLocalizedMessage( ) );
	}

}
 
Example 12
Source File: ScheduleClassAdapter.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
public void updateTime() {
    Calendar cal = Calendar.getInstance();
    int day = cal.get(Calendar.DAY_OF_WEEK) - 2;
    String time = cal.get(Calendar.HOUR) + (cal.get(Calendar.MINUTE) >= 30 ? ":30" : ":00")
            + (cal.get(Calendar.AM_PM) == Calendar.PM ? "pm" : "");

    if (day < 5 && day >= 0 && cal.get(Calendar.HOUR_OF_DAY) <= 22
            && cal.get(Calendar.HOUR_OF_DAY) >= 6) {
        currentTimePos = day + 5 * timeToPos(time);
        currMinutes = cal.get(Calendar.MINUTE) % 30;
    }
}