List of usage examples for java.util Calendar PM
int PM
To view the source code for java.util Calendar PM.
Click Source Link
From source file:Main.java
public static void main(String[] args) { Calendar cal = new GregorianCalendar(); System.out.println(cal.getTime()); cal.set(Calendar.AM_PM, Calendar.PM); System.out.println(cal.getTime()); }
From source file:Main.java
public static Date buildShiftEndTime(int startHour, int startMin, int startAmPm, int endHour, int endMin, int endAmPm) { endHour = endHour == 12 ? 0 : endHour; calendar.clear();//w w w .j a v a2s. co m calendar.set(Calendar.HOUR, endHour); calendar.set(Calendar.MINUTE, endMin); calendar.set(Calendar.AM_PM, endAmPm); if (startAmPm == Calendar.PM && endAmPm == Calendar.AM) { calendar.add(Calendar.DAY_OF_MONTH, 1); } return calendar.getTime(); }
From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java
public static void setAlarms(Context context) { //First cancelling all alarms cancelAlarms(context);/*from w w w . ja v a2s. c o m*/ //Set alarms list DataBaseManager dataBaseManager = DataBaseManager.getInstance(context); List<Alarm> alarmList = AlarmDataBase.getAlarmList(dataBaseManager); int alarmActivatedCount = 0; for (Alarm alarm : alarmList) { if (alarm.getActivated() == 1) { setAlarm(context, alarm); alarmActivatedCount++; } } AlarmUtilities.setStatusBarIcon(context, alarmActivatedCount > 0); Calendar day = Calendar.getInstance(); day.set(Calendar.DAY_OF_MONTH, 28); day.set(Calendar.MONTH, 8); day.set(Calendar.HOUR, 11); day.set(Calendar.AM_PM, Calendar.PM); if ((day.getTimeInMillis() - Calendar.getInstance().getTimeInMillis()) > 0) { setAlarmCumple(context); } }
From source file:com.brayanarias.alarmproject.receiver.AlarmReceiver.java
private static void setAlarm(Context context, Alarm alarm) { try {/* w ww .j ava 2s . c o m*/ PendingIntent pendingIntent = createPendingIntent(context, alarm); AlarmManager alarmManager = getAlarmManager(context); Calendar actual = Calendar.getInstance(); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); Calendar calendar = (Calendar) actual.clone(); int ampm = alarm.getAmPm().equals("AM") ? Calendar.AM : Calendar.PM; if (alarm.getHour() == 12) { calendar.set(Calendar.HOUR, 0); } else { calendar.set(Calendar.HOUR, alarm.getHour()); } calendar.set(Calendar.AM_PM, ampm); calendar.set(Calendar.MINUTE, alarm.getMinute()); int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); if (actual.getTimeInMillis() >= calendar.getTimeInMillis()) { if (alarm.getDaysOfAlamr().equals("0000000")) { calendar.add(Calendar.DATE, 1); } else { calendar.add(Calendar.DATE, getDaysFromNextAlarm(alarm.getDaysOfAlamr())); } } else { if (!AlarmUtilities.isToday(alarm.getDaysOfAlamr(), day)) { calendar.add(Calendar.DATE, getDaysFromNextAlarm(alarm.getDaysOfAlamr())); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AlarmManager.AlarmClockInfo clockInfo = new AlarmManager.AlarmClockInfo(calendar.getTimeInMillis(), pendingIntent); alarmManager.setAlarmClock(clockInfo, pendingIntent); } else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); } } catch (Exception e) { Log.e(tag, e.getLocalizedMessage(), e); } }
From source file:org.syncope.console.wicket.markup.html.form.DateTimeFieldPanel.java
public DateTimeFieldPanel(final String id, final String name, final IModel<Date> model, final boolean active, final String datePattern) { super(id, name, model, active); this.datePattern = datePattern; field = new DateTimeField("field", model); final Calendar cal = Calendar.getInstance(); field.get("hours").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override/*from w ww . jav a 2 s . co m*/ protected void onUpdate(AjaxRequestTarget art) { if (((DateTimeField) field).getHours() > 12) { cal.set(Calendar.HOUR_OF_DAY, ((DateTimeField) field).getHours()); } else { cal.set(Calendar.HOUR, ((DateTimeField) field).getHours()); } field.setModelObject(cal.getTime()); } }); field.get("minutes").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { cal.set(Calendar.MINUTE, ((DateTimeField) field).getMinutes()); field.setModelObject(cal.getTime()); } }); field.get("date").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { cal.setTime(((DateTimeField) field).getDate()); if ("PM".equals("" + ((DateTimeField) field).getAmOrPm())) { cal.set(Calendar.AM_PM, Calendar.PM); } else { cal.set(Calendar.AM_PM, Calendar.AM); } field.setModelObject(cal.getTime()); } }); field.get("amOrPmChoice").add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = -1107858522700306810L; @Override protected void onUpdate(final AjaxRequestTarget target) { if ("PM".equals("" + ((DateTimeField) field).getAmOrPm())) { cal.set(Calendar.AM_PM, Calendar.PM); } else { cal.set(Calendar.AM_PM, Calendar.AM); } field.setModelObject(cal.getTime()); } }); add(field.setLabel(new Model(name)).setOutputMarkupId(true)); }
From source file:com.liferay.blade.samples.springmvc.SpringMVCPortletViewController.java
/** * Handles the action when the action key is <code>updateFoo</code>. This is * the case when Foo is added and updated. * * @param actionRequest the action request * @param response the action response/*from www . j av a 2 s. c om*/ * @throws Exception if an exception occurred */ @ActionMapping(params = "action=updateFoo") public void updateFoo(ActionRequest actionRequest, ActionResponse response) throws Exception { // See if there is an existing Foo ID. long fooId = ParamUtil.getLong(actionRequest, "fooId"); // Extract the form field values. String field1 = ParamUtil.getString(actionRequest, "field1"); boolean field2 = ParamUtil.getBoolean(actionRequest, "field2"); int field3 = ParamUtil.getInteger(actionRequest, "field3"); String field5 = ParamUtil.getString(actionRequest, "field5"); // Convert the calendar details into a date. int dateMonth = ParamUtil.getInteger(actionRequest, "field4Month"); int dateDay = ParamUtil.getInteger(actionRequest, "field4Day"); int dateYear = ParamUtil.getInteger(actionRequest, "field4Year"); int dateHour = ParamUtil.getInteger(actionRequest, "field4Hour"); int dateMinute = ParamUtil.getInteger(actionRequest, "field4Minute"); int dateAmPm = ParamUtil.getInteger(actionRequest, "field4AmPm"); if (dateAmPm == Calendar.PM) { dateHour += 12; } Date field4 = PortalUtil.getDate(dateMonth, dateDay, dateYear, dateHour, dateMinute, PortalException.class); // If the Foo ID is less than or equal to zero, add a new Foo. if (fooId <= 0) { if (_log.isInfoEnabled()) { _log.info("Adding a new foo..."); } // Create the Foo. Foo foo = FooLocalServiceUtil.createFoo(0); // Set the Foo's fields. foo.setField1(field1); foo.setField2(field2); foo.setField3(field3); foo.setField4(field4); foo.setField5(field5); // Invoke the service layer to add the foo. FooLocalServiceUtil.addFooWithoutId(foo); } else { if (_log.isInfoEnabled()) { _log.info("Updating a new foo..."); } // Retrieve the current Foo during the update. Foo foo = FooLocalServiceUtil.fetchFoo(fooId); // Update the Foo's fields. foo.setFooId(fooId); foo.setField1(field1); foo.setField2(field2); foo.setField3(field3); foo.setField4(field4); foo.setField5(field5); // Invoke the service layer to update the Foo. FooLocalServiceUtil.updateFoo(foo); } }
From source file:org.kuali.kfs.pdp.businessobject.PaymentDetail.java
/** * Determines if the disbursement date is past the number of days old (configured in system parameter) in which actions can take * place/*from w w w . j a v a 2 s .c om*/ * * @return true if actions are allowed on disbursement, false otherwise */ public boolean isDisbursementActionAllowed() { if (paymentGroup.getDisbursementDate() == null) { if (PdpConstants.PaymentStatusCodes.EXTRACTED.equals(paymentGroup.getPaymentStatus().getCode())) { return false; } return true; } String daysStr = SpringContext.getBean(ParameterService.class).getParameterValueAsString( PaymentDetail.class, PdpParameterConstants.DISBURSEMENT_CANCELLATION_DAYS); int days = Integer.valueOf(daysStr); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, (days * -1)); c.set(Calendar.HOUR, 12); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.set(Calendar.AM_PM, Calendar.AM); Timestamp lastDisbursementActionDate = new Timestamp(c.getTimeInMillis()); Calendar c2 = Calendar.getInstance(); c2.setTime(paymentGroup.getDisbursementDate()); c2.set(Calendar.HOUR, 11); c2.set(Calendar.MINUTE, 59); c2.set(Calendar.SECOND, 59); c2.set(Calendar.MILLISECOND, 59); c2.set(Calendar.AM_PM, Calendar.PM); Timestamp disbursementDate = new Timestamp(c2.getTimeInMillis()); // date is equal to or after lastActionDate Allowed return ((disbursementDate.compareTo(lastDisbursementActionDate)) >= 0); }
From source file:MailDateFormatter.java
/** * A method that returns a string rapresenting a date. * * @param date the date//from w w w . j a va 2 s . c om * * @param format the format as one of * FORMAT_MONTH_DAY, * FORMAT_MONTH_DAY_YEAR, * FORMAT_HOURS_MINUTES, * FORMAT_HOURS_MINUTES_SECONDS * FORMAT_DAY_MONTH * FORMAT_DAY_MONTH_YEAR * constants * * @param separator the separator to be used */ public static String getFormattedStringFromDate(Date date, int format, String separator) { Calendar cal = Calendar.getInstance(); cal.setTime(date); StringBuffer ret = new StringBuffer(); switch (format) { case FORMAT_HOURS_MINUTES: //if pm and hour == 0 we want to write 12, not 0 if (cal.get(Calendar.AM_PM) == Calendar.PM && cal.get(Calendar.HOUR) == 0) { ret.append("12"); } else { ret.append(cal.get(Calendar.HOUR)); } ret.append(separator).append(printTwoDigits(cal.get(Calendar.MINUTE))).append(getAMPM(cal)); break; case FORMAT_HOURS_MINUTES_SECONDS: //if pm and hour == 0 we want to write 12, not 0 if (cal.get(Calendar.AM_PM) == Calendar.PM && cal.get(Calendar.HOUR) == 0) { ret.append("12"); } else { ret.append(cal.get(Calendar.HOUR)); } ret.append(separator).append(printTwoDigits(cal.get(Calendar.MINUTE))).append(separator) .append(cal.get(Calendar.SECOND)).append(getAMPM(cal)); break; case FORMAT_MONTH_DAY: ret.append(cal.get(Calendar.MONTH) + 1).append(separator).append(cal.get(Calendar.DAY_OF_MONTH)); break; case FORMAT_DAY_MONTH: ret.append(cal.get(Calendar.DAY_OF_MONTH)).append(separator).append(cal.get(Calendar.MONTH) + 1); break; case FORMAT_MONTH_DAY_YEAR: ret.append(cal.get(Calendar.MONTH) + 1).append(separator).append(cal.get(Calendar.DAY_OF_MONTH)) .append(separator).append(cal.get(Calendar.YEAR)); break; case FORMAT_DAY_MONTH_YEAR: ret.append(cal.get(Calendar.DAY_OF_MONTH)).append(separator).append(cal.get(Calendar.MONTH) + 1) .append(separator).append(cal.get(Calendar.YEAR)); break; default: // Log.error("getFormattedStringFromDate: invalid format ("+ // format+")"); } return ret.toString(); }
From source file:org.sakaiproject.user.impl.PrecachingDbUserService.java
/** UVa SAK-1382: replace Aaron's init() code to schedule one task to run at the same time each day * add a 2nd task "onetimeTask" to run immediately." *//*from w w w . j av a 2 s .c o m*/ public void init() { super.init(); if (log.isDebugEnabled()) { log.debug( "init(): (grand-super) BaseUserDirectoryService includes this general cache just created in its code, m_callCache==" + m_callCache); log.debug( "init(): (super) DbUserService includes this eid/id map, wired in user-components.xml, cache==" + cache); } // LOAD the various sakai config options Boolean runOnStartup = serverConfigurationService().getBoolean("precache.users.run.startup", false); Boolean runDaily = serverConfigurationService().getBoolean("precache.users.run.daily", false); String cacheTimeString = serverConfigurationService().getString("precache.users.refresh.time", "04:00"); this.siteUserIdsQuery = serverConfigurationService().getString("precache.users.userlist.query", this.siteUserIdsQuery); this.logUsersRemoved = serverConfigurationService().getBoolean("precache.users.log.usersRemoved", this.logUsersRemoved); this.logUsersNotRemoved = serverConfigurationService().getBoolean("precache.users.log.usersNotRemoved", this.logUsersNotRemoved); this.logUsersAccessed = serverConfigurationService().getBoolean("precache.users.log.usersAccessed", this.logUsersAccessed); this.logUsersNotAccessed = serverConfigurationService().getBoolean("precache.users.log.usersNotAccessed", this.logUsersNotAccessed); Calendar cal = Calendar.getInstance(); if (runOnStartup) { log.info("init() scheduling user precache for startup run"); // set up onetime task to run after short delay cal.setTime(new Date()); cal.add(Calendar.MINUTE, 5); Date onetimeTaskStart = cal.getTime(); onetimeTask = new UserCacheTimerTask(); bootTimer.schedule(onetimeTask, onetimeTaskStart); log.info("User precache refresh onetime task scheduled to run in 5 minutes without repetition."); } else { log.info("User precache not scheduled for startup run"); } if (runDaily) { // set up recurring task cal.setTime(new Date()); cal.add(Calendar.DATE, 1); // start tomorrow long recurringTaskPeriod = 24l * 60l * 60l * 1000l; log.info("User precache will schedule recurring task every 24 hours, beginning tomorrow"); try { String[] parts = cacheTimeString.trim().split(":"); Integer hour = new Integer(parts[0]); if (hour < 12) { cal.set(Calendar.AM_PM, Calendar.AM); } else { cal.set(Calendar.AM_PM, Calendar.PM); } cal.set(Calendar.HOUR, hour); cal.set(Calendar.MINUTE, new Integer(parts[1])); Date recurringTaskStart = cal.getTime(); scheduledTask = new UserCacheTimerTask(); dailyTimer.scheduleAtFixedRate(scheduledTask, recurringTaskStart, recurringTaskPeriod); log.info("User precache scheduled for daily run at " + cacheTimeString); } catch (RuntimeException e) { log.error( "User precache: Didn't schedule user cache refresh: Bad config?, it should be like: 'precache.users.refresh.time = 04:00' : " + e.getMessage(), e); } } else { log.info("User precache not scheduled for daily run"); } }
From source file:com.etime.ETimeUtils.java
/** * Parse a Punch from a given string. The format is assumed to be "12:00AM". All other calendar fields are set * to the current days value. The day, month, year, timezone and other misc fields are set to the current days value. * * @param punchStr The String to be parsed for the punch * @return the parsed Punch// w w w.java2 s.c om */ private static Punch getPunchFromString(String punchStr) { Punch punch = new Punch(); Calendar calendar; Pattern punchPattern = Pattern.compile("(\\d+):(\\d+)(A|P)M");//Format is "12:00PM" Matcher punchMatcher = punchPattern.matcher(punchStr); if (!punchMatcher.find()) { return null; } int hour = Integer.parseInt(punchMatcher.group(1)); int min = Integer.parseInt(punchMatcher.group(2)); calendar = Calendar.getInstance(); int hour24; if (punchMatcher.group(3).equals("A")) { calendar.set(Calendar.AM_PM, Calendar.AM); calendar.set(Calendar.HOUR, hour); if (hour == 12) { hour24 = 0; } else { hour24 = hour; } } else { calendar.set(Calendar.AM_PM, Calendar.PM); calendar.set(Calendar.HOUR, hour); if (hour != 12) { hour24 = hour + 12; } else { hour24 = hour; } } calendar.set(Calendar.HOUR_OF_DAY, hour24); calendar.set(Calendar.MINUTE, min); calendar.set(Calendar.SECOND, 0); punch.setCalendar(calendar); return punch; }