Java Code Examples for java.util.Calendar#AM

The following examples show how to use java.util.Calendar#AM . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Quelea   File: Clock.java    License: 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
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 Project: cathode   File: DateStringUtils.java    License: 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 4
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 5
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 6
Source Project: NewXmPluginSDK   File: TimePicker.java    License: 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 7
@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 8
/**
 * 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
/**
 * 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 10
/**
 * 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 11
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 12
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 13
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 14
Source Project: NIM_Android_UIKit   File: TimeUtil.java    License: 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 15
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 16
Source Project: TimePicker   File: TimePicker.java    License: 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 17
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 18
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 19
private String getAmPmString(int amPm) {
    return amPm == Calendar.AM ? mAmString : mPmString;
}
 
Example 20
Source Project: android_9.0.0_r45   File: DateUtils.java    License: 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];
}