Java Code Examples for java.util.Calendar#AM

The following examples show how to use java.util.Calendar#AM . 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: Clock.java    From Quelea with GNU General Public License v3.0 7 votes vote down vote up
private void bindToTime() {
    Timeline timeline = new Timeline(
            new KeyFrame(Duration.seconds(0), (ActionEvent actionEvent) -> {
                Calendar time = Calendar.getInstance();
                String hourString;
                boolean s24h = QueleaProperties.get().getUse24HourClock();
                if (s24h) {
                    hourString = pad(2, '0', time.get(Calendar.HOUR_OF_DAY) + "");
                } else {
                    hourString = pad(2, '0', time.get(Calendar.HOUR) + "");
                }
                String minuteString = pad(2, '0', time.get(Calendar.MINUTE) + "");
                String text1 = hourString + ":" + minuteString;
        if (!s24h) {
            text1 += (time.get(Calendar.AM_PM) == Calendar.AM) ? " AM" : " PM";
        }
        setText(text1);
    }),
            new KeyFrame(Duration.seconds(1))
    );
    timeline.setCycleCount(Animation.INDEFINITE);
    timeline.play();
}
 
Example 2
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 3
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 4
Source File: DateStringUtils.java    From cathode with Apache License 2.0 6 votes vote down vote up
public static String getTimeString(long millis, boolean is24HourFormat) {
  StringBuilder sb = new StringBuilder();
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(millis);

  if (is24HourFormat) {
    sb.append(cal.get(Calendar.HOUR_OF_DAY));
  } else {
    sb.append(cal.get(Calendar.HOUR));
  }

  sb.append(":").append(String.format(Locale.US, "%02d", cal.get(Calendar.MINUTE)));

  if (!is24HourFormat) {
    sb.append(" ");
    final int ampm = cal.get(Calendar.AM_PM);
    if (ampm == Calendar.AM) {
      sb.append("am");
    } else {
      sb.append("pm");
    }
  }

  return sb.toString();
}
 
Example 5
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 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: 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 8
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 9
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 10
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 11
Source File: LocalMeetingModel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public LocalMeetingModel(Meeting meeting) {
	this.location = meeting.getLocation();
	this.monday = meeting.isMonday();
	this.tuesday = meeting.isTuesday();
	this.wednesday = meeting.isWednesday();
	this.thursday = meeting.isThursday();
	this.friday = meeting.isFriday();
	this.saturday = meeting.isSaturday();
	this.sunday = meeting.isSunday();
	this.startTimeString = JsfUtil.convertTimeToString(meeting.getStartTime());
	if(startTimeString == null) {
		startTimeString = JsfUtil.getLocalizedMessage("section_start_time_default");
	}

	this.endTimeString = JsfUtil.convertTimeToString(meeting.getEndTime());
	if(endTimeString == null) {
		endTimeString = JsfUtil.getLocalizedMessage("section_end_time_default");
	}
	
	Calendar cal = new GregorianCalendar();
	if(meeting.getStartTime() == null) {
		this.startTimeAm = true;
	} else {
		cal.setTime(meeting.getStartTime());
		if(log.isDebugEnabled()) log.debug("cal.get(Calendar.AM_PM) = " + cal.get(Calendar.AM_PM));
		this.startTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM);
	}
	if(meeting.getEndTime() == null) {
		this.endTimeAm = true;
	} else {
		cal.setTime(meeting.getEndTime());
		if(log.isDebugEnabled()) log.debug("cal.get(Calendar.AM_PM) = " + cal.get(Calendar.AM_PM));
		this.endTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM);
	}
}
 
Example 12
Source File: ExitSessionFrameHandler.java    From ib-controller with GNU General Public License v3.0 5 votes vote down vote up
private boolean adjustExitSessionTime(Window window) {
    Date newLogoffTime =new Date(System.currentTimeMillis() - 5 * 60 * 1000);
    Calendar cal = Calendar.getInstance();
    cal.setTime(newLogoffTime);
    String newLogoffTimeText = new SimpleDateFormat("hh:mm").format(newLogoffTime);

    SwingUtils.setTextField(window, 0, newLogoffTimeText);

    if (cal.get(Calendar.AM_PM) == Calendar.AM) {
        if (! SwingUtils.setRadioButtonSelected(window, "AM" /*, true*/)) return false;
    } else {
        if (! SwingUtils.setRadioButtonSelected(window, "PM" /*, true*/)) return false;
    }

    if (SwingUtils.clickButton(window, "Update")) {
    } else if (SwingUtils.clickButton(window, "Aktualisieren")) {
    } else {
        return false;
    }

    if (SwingUtils.clickButton(window, "Close")) {
    } else if (SwingUtils.clickButton(window, "Schliessen")) {
    } else {
        return false;
    }

    Utils.logToConsole("AutoLogoff time changed to " +
                        newLogoffTimeText +
                        (cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"));
    return true;
}
 
Example 13
Source File: TimePicker.java    From TimePicker with Apache License 2.0 5 votes vote down vote up
public void setTime(Date date) {
    calendar.setTime(date);
    hour = calendar.get(Calendar.HOUR);
    minutes = calendar.get(Calendar.MINUTE);
    amPm = calendar.get(Calendar.AM_PM) == Calendar.AM;
    degrees = ((hour * 30) + 270) % 360;
    angle = Math.toRadians(degrees);
    degrees = ((double) minutes / 2);
    angle += Math.toRadians(degrees) + .001;
    invalidate();
}
 
Example 14
Source File: LocalMeetingModel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public LocalMeetingModel(Meeting meeting) {
	this.location = meeting.getLocation();
	this.monday = meeting.isMonday();
	this.tuesday = meeting.isTuesday();
	this.wednesday = meeting.isWednesday();
	this.thursday = meeting.isThursday();
	this.friday = meeting.isFriday();
	this.saturday = meeting.isSaturday();
	this.sunday = meeting.isSunday();
	this.startTimeString = JsfUtil.convertTimeToString(meeting.getStartTime());
	if(startTimeString == null) {
		startTimeString = JsfUtil.getLocalizedMessage("section_start_time_default");
	}

	this.endTimeString = JsfUtil.convertTimeToString(meeting.getEndTime());
	if(endTimeString == null) {
		endTimeString = JsfUtil.getLocalizedMessage("section_end_time_default");
	}
	
	Calendar cal = new GregorianCalendar();
	if(meeting.getStartTime() == null) {
		this.startTimeAm = true;
	} else {
		cal.setTime(meeting.getStartTime());
		if(log.isDebugEnabled()) log.debug("cal.get(Calendar.AM_PM) = " + cal.get(Calendar.AM_PM));
		this.startTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM);
	}
	if(meeting.getEndTime() == null) {
		this.endTimeAm = true;
	} else {
		cal.setTime(meeting.getEndTime());
		if(log.isDebugEnabled()) log.debug("cal.get(Calendar.AM_PM) = " + cal.get(Calendar.AM_PM));
		this.endTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM);
	}
}
 
Example 15
Source File: TimeUtil.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
public static String getBeijingNowTimeString(String format) {
    TimeZone timezone = TimeZone.getTimeZone("Asia/Shanghai");

    Date date = new Date(currentTimeMillis());
    SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
    formatter.setTimeZone(timezone);

    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTimeZone(timezone);
    String prefix = gregorianCalendar.get(Calendar.AM_PM) == Calendar.AM ? "上午" : "下午";

    return prefix + formatter.format(date);
}
 
Example 16
Source File: ItemEntity1.java    From MultiTypeRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
public ItemEntity1(String title, String content, int flag) {
    this.title = title;
    this.content = content;
    this.img = getImg(flag);
    long currentTimeMillis = System.currentTimeMillis();
    long timeMillis = currentTimeMillis - new Random().nextInt(1000 * 60 * 60 * 24 * 5);
    final Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timeMillis);
    int time_flag = calendar.get(Calendar.AM_PM);
    this.time = (String) DateFormat.format("HH:mm", calendar);
    this.timeFlag = time_flag == Calendar.AM ? "AM" : "PM";
    this.id = TextUtils.isEmpty(title) ? currentTimeMillis : MD5Util.stringToMD5(title).hashCode();
}
 
Example 17
Source File: ExitSessionFrameHandler.java    From IBC with GNU General Public License v3.0 5 votes vote down vote up
private boolean adjustExitSessionTime(Window window) {
    Date newLogoffTime =new Date(System.currentTimeMillis() - 5 * 60 * 1000);
    Calendar cal = Calendar.getInstance();
    cal.setTime(newLogoffTime);
    String newLogoffTimeText = new SimpleDateFormat("hh:mm").format(newLogoffTime);

    SwingUtils.setTextField(window, 0, newLogoffTimeText);

    if (cal.get(Calendar.AM_PM) == Calendar.AM) {
        if (! SwingUtils.setRadioButtonSelected(window, "AM" /*, true*/)) return false;
    } else {
        if (! SwingUtils.setRadioButtonSelected(window, "PM" /*, true*/)) return false;
    }

    if (SwingUtils.clickButton(window, "Update")) {
    } else if (SwingUtils.clickButton(window, "Apply")) {  // TWS 974
    } else if (SwingUtils.clickButton(window, "Aktualisieren")) {
    } else {
        return false;
    }

    if (SwingUtils.clickButton(window, "Close")) {
    } else if (SwingUtils.clickButton(window, "OK")) {  // TWS 974
    } else if (SwingUtils.clickButton(window, "Schliessen")) {
    } else {
        return false;
    }

    Utils.logToConsole("AutoLogoff time changed to " +
                        newLogoffTimeText +
                        (cal.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"));
    return true;
}
 
Example 18
Source File: TimeSliderRangePicker.java    From timerangepicker with Apache License 2.0 5 votes vote down vote up
public void updateArcColor() {
    if(start.get(Calendar.AM_PM) == Calendar.AM){
        mArcColor = arcColorAM;
        mStartThumbImage = thumbImageAM;
        mEndThumbImage = thumbEndImageAM;
    }
    else
    {
        mArcColor =  arcColorPM;
        mStartThumbImage = thumbImagePM;
        mEndThumbImage = thumbEndImagePM;
    }
}
 
Example 19
Source File: DigitalWatchFaceService.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
private String getAmPmString(int amPm) {
    return amPm == Calendar.AM ? mAmString : mPmString;
}
 
Example 20
Source File: DateUtils.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Return a localized string for AM or PM.
 * @param ampm Either {@link Calendar#AM Calendar.AM} or {@link Calendar#PM Calendar.PM}.
 * @throws IndexOutOfBoundsException if the ampm is out of bounds.
 * @return Localized version of "AM" or "PM".
 * @deprecated Use {@link java.text.SimpleDateFormat} instead.
 */
@Deprecated
public static String getAMPMString(int ampm) {
    return LocaleData.get(Locale.getDefault()).amPm[ampm - Calendar.AM];
}