List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:com.acmeair.web.LoaderREST.java
private static Date getArrivalTime(Date departureTime, int mileage) { double averageSpeed = 600.0; // 600 miles/hours double hours = (double) mileage / averageSpeed; // miles / miles/hour = // hours double partsOfHour = hours % 1.0; int minutes = (int) (60.0 * partsOfHour); Calendar c = Calendar.getInstance(); c.setTime(departureTime); c.add(Calendar.HOUR, (int) hours); c.add(Calendar.MINUTE, minutes); return c.getTime(); }
From source file:com.scf.core.EnvTest.java
public static List<Date> getSelectableDateTimeList() { String deliveryCycle = "7"; if (StringUtils.isEmpty(deliveryCycle)) { throw new AppException(ExCode.SYS_002); }/*from w w w .jav a 2 s . c o m*/ Date curDate = DatetimeUtilies.currentDay(); List<Date> selectableDateList = new ArrayList<Date>(Integer.valueOf(deliveryCycle)); Calendar tomorrow = Calendar.getInstance(); tomorrow.setTime(curDate); int i = 0; String[] d = { "07", "16" }; while (i < Integer.valueOf(deliveryCycle)) { tomorrow.add(Calendar.DATE, 1); for (String deliveryHour : d) { Calendar tomorrowDetail = Calendar.getInstance(); tomorrowDetail.setTime(tomorrow.getTime()); tomorrowDetail.set(Calendar.HOUR_OF_DAY, Integer.parseInt(deliveryHour)); selectableDateList.add(tomorrowDetail.getTime()); } i++; } return selectableDateList; }
From source file:com.mxep.web.common.persistence.SearchFilter.java
/** * searchParamskey?OPERATOR_FIELDNAME//from w w w.ja v a2s . c o m */ public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) { Map<String, SearchFilter> filters = Maps.newHashMap(); for (Entry<String, Object> entry : searchParams.entrySet()) { // String key = entry.getKey(); Object value = entry.getValue(); if (value != null && StringUtils.isBlank(value.toString())) { continue; } // operatorfiledAttribute String[] names = StringUtils.split(key, "_"); if (names.length < 2) { throw new IllegalArgumentException(key + " is not a valid search filter name"); } String filedName = ""; for (int i = 1; i < names.length; i++) { filedName += names[i]; if ((i + 1) < names.length) { filedName += "."; } } Operator operator = getOperator(names[0]); if (null == operator) { continue; } // searchFilter if (isValidDate(value.toString())) { try { Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd"); // ? if (operator.equals(Operator.LT) || operator.equals(Operator.LTE)) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, 1); date = cal.getTime(); } // ???? if (operator.equals(Operator.GT) || operator.equals(Operator.GTE)) { Calendar cal = Calendar.getInstance(); cal.setTime(date); date = cal.getTime(); } value = date; } catch (Exception e) { e.printStackTrace(); } } else if (isValidDateTime(value.toString())) { try { Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd HH:mm:ss"); value = date; } catch (Exception e) { e.printStackTrace(); } } // searchFilter SearchFilter filter = new SearchFilter(filedName, operator, value); filters.put(key, filter); } return filters; }
From source file:com.qdum.llhb.common.utils.DateUtils.java
/** * ??// w ww .ja v a 2 s . c om * * @param date1 * @param date2 * @return */ public static Boolean isSameWeek(Date date1, Date date2) { Calendar c = Calendar.getInstance(); c.setTime(date1); Calendar c2 = Calendar.getInstance(); c2.setTime(date2); int week1 = c.get(Calendar.WEEK_OF_YEAR); int week2 = c2.get(Calendar.WEEK_OF_YEAR); if (week1 == week2) { return Boolean.TRUE; } else { return Boolean.FALSE; } }
From source file:com.qdum.llhb.common.utils.DateUtils.java
/** * ??//from ww w .j ava 2s . co m * * @return */ public static Boolean isSameMonth(Date date1, Date date2) { Calendar c = Calendar.getInstance(); c.setTime(date1); Calendar c2 = Calendar.getInstance(); c2.setTime(date2); int month = c.get(Calendar.MONTH); int month2 = c2.get(Calendar.MONTH); if (month == month2) { return Boolean.TRUE; } else { return Boolean.FALSE; } }
From source file:org.openmeetings.utils.math.TimezoneUtil.java
/** * We ignore the fact that a Date Object is always in UTC internally and * treat it as if it contains only dd.mm.yyyy HH:mm:ss. We need to do this * cause we cannot trust the Date Object send from the client. We have the * timeZone information additional to the Date, so we use it to transform it * now to a Calendar Object./*from w ww . j a v a 2 s . com*/ * * @param dateTime * @param timezone * @return */ public static Calendar getCalendarInTimezone(String dateTimeStr, TimeZone timezone) { Date dateTime = CalendarPatterns.parseImportDate(dateTimeStr); Calendar calOrig = Calendar.getInstance(); calOrig.setTime(dateTime); Calendar cal = Calendar.getInstance(timezone); cal.set(Calendar.YEAR, calOrig.get(Calendar.YEAR)); cal.set(Calendar.MONTH, calOrig.get(Calendar.MONTH)); cal.set(Calendar.DATE, calOrig.get(Calendar.DATE)); cal.set(Calendar.HOUR_OF_DAY, calOrig.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, calOrig.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, calOrig.get(Calendar.SECOND)); return cal; }
From source file:com.iflytek.kcloud.web.utils.BookDateUtil.java
/** * getDay:?. <br/>/*from ww w . jav a2 s. c o m*/ * * @param gap (0,1,-1....) * @return * @throws ParseException * @author zyyang3 * @since JDK 1.6 */ public static String getDay(String time, int gap) throws ParseException { Calendar cal = Calendar.getInstance(); Date datetmp = sdf.parse(time); cal.setTime(datetmp); cal.add(Calendar.DAY_OF_MONTH, gap); Date date = cal.getTime(); String day = DateFormatUtils.format(date, "yyyy-MM-dd"); return day; }
From source file:com.augmentum.common.util.DateUtil.java
public static Date getTruncatedDate(int mon, int day, int year) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.set(Calendar.MONTH, mon); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.YEAR, year); return DateUtils.truncate(cal.getTime(), Calendar.DAY_OF_MONTH); }
From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java
/** * /*from www. jav a 2s . com*/ * @param date * @param duration * Example: Date date = subtractOrAddDayDuration(new Date(), -2); * // Result: the last 2 days * * Date date = subtractOrAddDayDuration(new Date(), 2); // * Result: the next 2 days * @return */ public static Date subtractOrAddDayDuration(Date date, int duration) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, duration); Date dateExpect = cal.getTime(); return dateExpect; }
From source file:com.streamhub.StreamHubLicenseGenerator.java
private static JPanel createMacAddressRow() { JPanel macAddressPanel = new JPanel(new FlowLayout()); Calendar yesterday = Calendar.getInstance(); yesterday.setTime(new Date()); yesterday.add(Calendar.DAY_OF_MONTH, -1); Calendar expiry = Calendar.getInstance(); expiry.setTime(yesterday.getTime()); expiry.add(Calendar.DAY_OF_MONTH, 60); JLabel macAddressLabel = new JLabel("MAC Address:"); JTextField macAddress = new JTextField(17); JLabel startDateLabel = new JLabel("Start Date"); final JFormattedTextField startDate = new JFormattedTextField(new SimpleDateFormat(DATE_FORMAT)); startDate.setValue(yesterday.getTime()); JLabel expiryDateLabel = new JLabel("Expiry Date"); final JFormattedTextField expiryDate = new JFormattedTextField(new SimpleDateFormat(DATE_FORMAT)); expiryDate.setValue(expiry.getTime()); startDate.addKeyListener(new KeyListener() { @Override//from ww w .j ava 2 s .c o m public void keyTyped(KeyEvent arg0) { // Get the new date and change expiry to suit Date date = (Date) startDate.getValue(); Calendar tempCal = Calendar.getInstance(); tempCal.setTime(date); tempCal.add(Calendar.DAY_OF_MONTH, 60); expiryDate.setValue(tempCal.getTime()); } @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } }); JComboBox edition = new JComboBox(new String[] { "web", "enterprise" }); JLabel nameLabel = new JLabel("Name:"); JTextField name = new JTextField(15); JLabel numUsersLabel = new JLabel("Num. Users:"); JTextField numUsers = new JTextField(DEFAULT_NUM_USERS); macAddressPanel.add(macAddressLabel); macAddressPanel.add(macAddress); macAddressPanel.add(startDateLabel); macAddressPanel.add(startDate); macAddressPanel.add(expiryDateLabel); macAddressPanel.add(expiryDate); macAddressPanel.add(edition); macAddressPanel.add(nameLabel); macAddressPanel.add(name); macAddressPanel.add(numUsersLabel); macAddressPanel.add(numUsers); return macAddressPanel; }