List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:es.logongas.encuestas.presentacion.controller.EncuestaController.java
private Curso getCursoFromDate(Date date) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date);// w w w . j a v a 2s. co m int anyoInicioCurso; int anyoActual = gc.get(GregorianCalendar.YEAR); int mesActual = gc.get(GregorianCalendar.MONTH); //A partir de Mayo estamos en el nuevo curso a efectos de las encuestas de matricula if (mesActual >= Calendar.MAY) { anyoInicioCurso = anyoActual; } else { anyoInicioCurso = anyoActual - 1; } CursoDAO cursoDAO = (CursoDAO) daoFactory.getDAO(Curso.class); Curso curso = cursoDAO.getByAnyoInicio(anyoInicioCurso); if (curso == null) { //Creamos un nuevo curso para este ao throw new RuntimeException("No existe el curso que empieza en el ao:" + anyoInicioCurso); } return curso; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ?2009-08-01/*from w w w. j a v a 2s . com*/ */ public static String addMonth(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(2, 1); // 2?1?(,) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ? ?2009-08-01/*from w w w . java2s . com*/ */ public static String subMonth(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(2, -1); // 2?1?(,) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:StocksTable5.java
public int retrieveData(final java.util.Date date) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date);//from w w w . j a v a 2s . c om int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); int year = calendar.get(Calendar.YEAR); final String query = "SELECT data.symbol, symbols.name, " + "data.last, data.open, data.change, data.changeproc, " + "data.volume FROM DATA INNER JOIN SYMBOLS " + "ON DATA.symbol = SYMBOLS.symbol WHERE " + "month(data.date1)=" + month + " AND day(data.date1)=" + day + " AND year(data.date1)=" + year; Thread runner = new Thread() { public void run() { try { // Load the JDBC-ODBC bridge driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:Market", "admin", ""); Statement stmt = conn.createStatement(); ResultSet results = stmt.executeQuery(query); boolean hasData = false; while (results.next()) { if (!hasData) { m_vector.removeAllElements(); hasData = true; } String symbol = results.getString(1); String name = results.getString(2); double last = results.getDouble(3); double open = results.getDouble(4); double change = results.getDouble(5); double changePr = results.getDouble(6); long volume = results.getLong(7); m_vector.addElement(new StockData(symbol, name, last, open, change, changePr, volume)); } results.close(); stmt.close(); conn.close(); if (!hasData) // We've got nothing m_result = 1; } catch (Exception e) { e.printStackTrace(); System.err.println("Load data error: " + e.toString()); m_result = -1; } m_date = date; Collections.sort(m_vector, new StockComparator(m_sortCol, m_sortAsc)); m_result = 0; } }; runner.start(); return m_result; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ?2009-08-01/*from w w w.j a v a 2s.c om*/ */ public static String addDay(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(5, 1); // 2?1?(....5) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:com.eryansky.common.utils.DateUtil.java
/** * ? ?2009-08-01/*from w w w . j a va 2 s . c om*/ */ public static String subDay(String strdate) { Date date = new Date(); // ?? String dateresult = null; // // ?? SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // ? GregorianCalendar gc = new GregorianCalendar(); try { date = df.parse(strdate); // ? } catch (ParseException e) { e.printStackTrace(); } gc.setTime(date); // gc? gc.add(5, -1); // 2?1?(....5) // ? gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE)); // ? dateresult = df.format(gc.getTime()); return dateresult; }
From source file:org.jahia.utils.maven.plugin.contentgenerator.ContentGeneratorService.java
/** * Format a date for inclusion in JCR XML file If date is null, current date * is used Format used: http://www.day.com/specs/jcr/1.0/6.2.5.1_Date.html * //w ww .ja v a 2s. c o m * @param date * @return formated date */ public String getDateForJcrImport(Date date) { GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance(); if (date != null) { gc.setTime(date); } StringBuffer sbNewDate = new StringBuffer(); // 2011-04-01T17:39:59.265+02:00 sbNewDate.append(gc.get(Calendar.YEAR)); sbNewDate.append("-"); sbNewDate.append(gc.get(Calendar.MONTH)); sbNewDate.append("-"); sbNewDate.append(gc.get(Calendar.DAY_OF_MONTH)); sbNewDate.append("T"); sbNewDate.append(gc.get(Calendar.HOUR_OF_DAY)); sbNewDate.append(":"); sbNewDate.append(gc.get(Calendar.MINUTE)); sbNewDate.append(":"); sbNewDate.append(gc.get(Calendar.SECOND)); sbNewDate.append("."); sbNewDate.append(gc.get(Calendar.MILLISECOND)); sbNewDate.append(gc.get(Calendar.ZONE_OFFSET)); return sbNewDate.toString(); }
From source file:org.nuclos.common2.SeriesUtils.java
/** * /*from w w w . j a v a 2 s . co m*/ * @param series * @param dateOrigin * @return the next date calculated by series from origin. * origin could be a calculated date (result >= origin) */ public static DateTime getSeriesNext(String series, DateTime dateOrigin) { if (series == null) return dateOrigin; GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(dateOrigin.getDate()); String[] split = org.apache.commons.lang.StringUtils.split(series, '|'); if (split.length > 0) { String modus = split[0]; if ("d".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int days = Integer.parseInt(split[3]); if (days == 0) { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } while (!isWorkingDay(calendar.get(GregorianCalendar.DAY_OF_WEEK))) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } if (days > 1) { calendar.add(GregorianCalendar.DAY_OF_MONTH, days - 1); } } } else if ("w".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int weeks = Integer.parseInt(split[3]); List<Integer> possibleWeekdays = new ArrayList<Integer>(); int firstSelectedWeekday = -1000; int lastWeekday = -1000; // use getWeekdayItems() in order to get the right start (end) of the week for (SeriesListItem sli : getWeekdayItems()) { boolean addWeekday = false; switch (sli.getId()) { case GregorianCalendar.MONDAY: if (split[4].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.TUESDAY: if (split[5].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.WEDNESDAY: if (split[6].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.THURSDAY: if (split[7].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.FRIDAY: if (split[8].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SATURDAY: if (split[9].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SUNDAY: if (split[10].equals("0") ? false : true) addWeekday = true; break; } if (addWeekday) { possibleWeekdays.add(sli.getId()); if (firstSelectedWeekday == -1000) firstSelectedWeekday = sli.getId(); } lastWeekday = sli.getId(); } // add one day if calculated date is before origin boolean weeksAdded = false; if (calendar.getTime().before(dateOrigin.getDate())) { if (lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); weeksAdded = true; } else { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } while (!possibleWeekdays.contains(new Integer(calendar.get(GregorianCalendar.DAY_OF_WEEK)))) { if (!weeksAdded && lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); } calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else if ("m".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("m1".equals(split[3])) { int day = Integer.parseInt(split[4]); int months = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int months = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } else if ("y".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("y1".equals(split[3])) { int day = Integer.parseInt(split[4]); int month = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int month = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } } return new DateTime(calendar.getTimeInMillis()); }
From source file:org.squale.welcom.outils.DateUtil.java
/** * @param beginDate date de dbut de la priode en Date * @param endDate date de fin de la priode en Date * @param weekend true pour que les jours fris tombant un week end soient comtabilis, false sinon. * @return retourne le nombre de jours fris dans la priode. *//* w ww . j a va 2s .c o m*/ public static int getNbPublicHolliday(final Date beginDate, final Date endDate, final boolean weekend) { if ((beginDate == null) || (endDate == null)) { return 0; } final GregorianCalendar gc = new GregorianCalendar(); // recupere l'anne de debut int by = getYearOfDate(gc, beginDate); // Recupere l'anne de fin int ey = getYearOfDate(gc, endDate); // Recupere les jours de vacance des 2 annes ArrayList ph = getPublicHolliday(by, ey); int nbph = 0; for (final Iterator iter = ph.iterator(); iter.hasNext();) { final Date d = (Date) iter.next(); gc.setTime(d); // Si les WEEK-END sont compatbili , les ajouter au compteur if (weekend) { if (isBetween(d, beginDate, endDate)) { nbph++; } } else { // Verifie que ce n'est pas un Samedi ou un dimance pour ompatibilit if ((gc.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) && (gc.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)) { if (isBetween(d, beginDate, endDate)) { nbph++; } } } } return nbph; }
From source file:oracle.retail.stores.pos.ado.utility.Utility.java
/** * This method checks if the entered expiry date of ID is valid. Returns false * if entered expiry date is before the current date. True otherwise. * @param expirationDate//from www. ja v a2s.c o m * @throws TenderException if not a valid expiration date */ public boolean isValidExpirationDate(String expirationDate) throws TenderException { boolean result = true; Date today = new Date(); EYSDate todayEYS = new EYSDate(today); String format = EYSDate.ID_EXPIRATION_DATE_FORMAT; Locale locale = LocaleMap.getLocale(LocaleConstantsIfc.DEFAULT_LOCALE); DateFormat dateFormat = new SimpleDateFormat(format, locale); Date date = null; EYSDate dateEYS = null; try { date = dateFormat.parse(expirationDate); dateEYS = new EYSDate(date); } catch (ParseException e) { throw new TenderException("Invalid expiration date format", TenderErrorCodeEnum.INVALID_EXPIRATION_DATE, e); } GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance(); gc.setTime(today); int thisMonth = gc.get(Calendar.MONTH); int thisYear = gc.get(Calendar.YEAR); gc.clear(); Calendar c = dateEYS.calendarValue(); gc.setTime(c.getTime()); if (dateEYS.before(todayEYS) && !((thisMonth == gc.get(Calendar.MONTH)) && (thisYear == gc.get(Calendar.YEAR)))) { result = false; } return result; }