List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:Main.java
/** * Method to check if a date is tomorrow * // w w w . j a va2 s. co m * @param theDate * the date to see if it is tomorrow * @return true of it is tomorrow */ public static boolean isTomorrow(Date theDate) { // Get a calendar with the events start time GregorianCalendar theCalendar = new GregorianCalendar(); theCalendar.setTime(theDate); // Get a calendar with current system time and change its value so it // can be used in comparison with the given date. Calendar tmpDate = Calendar.getInstance(); tmpDate.roll(Calendar.DAY_OF_YEAR, true); return tmpDate.get(Calendar.YEAR) == theCalendar.get(Calendar.YEAR) && tmpDate.get(Calendar.DAY_OF_YEAR) == theCalendar.get(Calendar.DAY_OF_YEAR); }
From source file:com.saax.gestorweb.util.DAOAleatorio.java
public static Date getDataByOffset(int offsetDataAtual, boolean up) { GregorianCalendar gc = new GregorianCalendar(); Date hoje = DateUtils.truncate(new Date(), Calendar.DATE); gc.setTime(hoje); // hoje truncando as horas for (int i = 0; i < offsetDataAtual; i++) { gc.roll(GregorianCalendar.DAY_OF_MONTH, up); if (gc.getActualMaximum(GregorianCalendar.DAY_OF_MONTH) == gc.get(GregorianCalendar.DAY_OF_MONTH)) { gc.roll(GregorianCalendar.MONTH, up); }//from www . j a v a 2 s . com } return DateUtils.truncate(new Date(gc.getTimeInMillis()), Calendar.DATE); }
From source file:com.projity.util.DateTime.java
/** * Get an integer for the date in form YYYYMMDD where the months go from 1 to 12 (unlike calendar where they go from 0 to 11) * @param date/* w w w . j a v a 2 s . co m*/ * @return */ public static int toId(long date) { GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date); return cal.get(Calendar.YEAR) * 10000 + (1 + cal.get(Calendar.MONTH)) * 100 + cal.get(Calendar.DAY_OF_MONTH); }
From source file:Main.java
private static void subtractField(GregorianCalendar g1, GregorianCalendar g2, int field) { // int value1 = g1.get( field ); int value2 = g2.get(field); if (field == Calendar.DAY_OF_MONTH) value2 -= 1;//from w ww.ja va2 s. co m g1.add(field, -value2); }
From source file:Spring.Repaso02.Principal.java
public static void demoPedido(PedidoDAO pedidodao, ProductoDAO productodao) { GregorianCalendar cal = inicializaCal(); ArrayList<Producto> ALP = productodao.consultaAll(cal); Cliente c = crearClienteEjemplo();//from ww w .j av a 2s . co m Pedido p = new Pedido(); p.setIdCliente(c.getIdCliente()); p.setFhPedido(cal); p.setIdPedido(1); p.setObservaciones("Prueba de pedido"); if (cal.get(Calendar.HOUR_OF_DAY) <= 12) { p.setfRecogida(cal); } else { GregorianCalendar aux = cal; aux.add(Calendar.DATE, 1); p.setfRecogida(aux); } ArrayList<PedidoLinea> pl = new ArrayList(); PedidoLinea aux; for (Producto producto : ALP) { aux = new PedidoLinea(); aux.setProducto(producto); aux.setCantidad(2); pl.add(aux); } p.setLineasPedido(pl); pedidodao.baja(p); pedidodao.alta(p); System.out.println(pedidodao.consulta(p.getIdPedido()).toString()); p.setObservaciones("Se ha modificado el pedido"); pedidodao.modificacion(p); System.out.println(pedidodao.consulta(p.getIdPedido()).toString()); System.out.println(pedidodao.consulta(c.getIdCliente(), cal).toString()); }
From source file:org.mifos.calendar.CalendarUtils.java
/** * Set the day of week according to given start day to the require weekday, i.e. so it matches the meeting week day. * * e.g. - If start date is Monday 9 June 2008 and meeting week day is Tuesday, then roll forward the date to Tuesday * 10 June 2008 - or if start date is Sunday 8 June 2008 and meeting week day is Saturday, then roll forward the * date to Saturday 14 June 2008 - or if start date is Tuesday 10 2008 June and meeting week day is Monday, then * roll forward the date to Monday 16 June 2008 - or if start date is Sunday 8 June 2008 and meeting week day is * Sunday, then keep the date as Sunday 8 June 2008 - or if start date is Saturday 7 June 2008 and meeting week day * is Sunday, then roll forward the date to Sunday 9 June 2008. *///from w ww. j a va 2 s .c om public static DateTime getFirstDateForWeek(final DateTime startDate, final int dayOfWeek) { /* * In Joda time MONDAY=1 and SUNDAY=7, so shift these to SUNDAY=1, SATURDAY=7 to match this class */ int calendarDayOfWeek = (dayOfWeek % 7) + 1; final GregorianCalendar firstDateForWeek = new GregorianCalendar(); firstDateForWeek.setTime(startDate.toDate()); int startDateWeekDay = firstDateForWeek.get(Calendar.DAY_OF_WEEK); int amountOfDaysToAdd = calendarDayOfWeek - startDateWeekDay; if (amountOfDaysToAdd < 0) { amountOfDaysToAdd += 7; } firstDateForWeek.add(Calendar.DAY_OF_WEEK, amountOfDaysToAdd); return new DateTime(firstDateForWeek.getTime()); }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getNextDateForMonthOnDate(final DateTime startDate, final int dayOfMonth, final int every) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate());// w w w . j a v a2s .co m gc.add(GregorianCalendar.MONTH, every); int M1 = gc.get(GregorianCalendar.MONTH); gc.set(GregorianCalendar.DATE, dayOfMonth); int M2 = gc.get(GregorianCalendar.MONTH); int daynum = dayOfMonth; while (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DATE, daynum - 1); M2 = gc.get(GregorianCalendar.MONTH); daynum--; } return new DateTime(gc.getTime().getTime()); }
From source file:oscar.oscarRx.data.RxPatientData.java
private static int calcAge(java.util.Date DOB) { if (DOB == null) return 0; GregorianCalendar now = new GregorianCalendar(); int curYear = now.get(Calendar.YEAR); int curMonth = (now.get(Calendar.MONTH) + 1); int curDay = now.get(Calendar.DAY_OF_MONTH); Calendar cal = new GregorianCalendar(); cal.setTime(DOB);/*from w w w .ja v a 2 s. c om*/ int iYear = cal.get(Calendar.YEAR); int iMonth = (cal.get(Calendar.MONTH) + 1); int iDay = cal.get(Calendar.DAY_OF_MONTH); int age = 0; if (curMonth > iMonth || (curMonth == iMonth && curDay >= iDay)) { age = curYear - iYear; } else { age = curYear - iYear - 1; } return age; }
From source file:DateUtils.java
public static final String getTimeFromDate(Date dt, String tzString) { try {//from w ww .j a va 2 s. co m GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dt); gc.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); ret.append(gc.get(Calendar.HOUR)); ret.append(":"); ret.append(gc.get(Calendar.MINUTE)); ret.append(" "); if (gc.get(Calendar.AM_PM) == 0) { ret.append("AM"); } else { ret.append("PM"); } return ret.toString(); } catch (Exception e) { return ""; } }
From source file:DateUtils.java
public static final String getDateTimeFromDate(Date dt, String tzString) { try {//from w w w .j a va 2 s . c om GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dt); gc.setTimeZone(TimeZone.getTimeZone(tzString)); StringBuffer ret = new StringBuffer(); ret.append(gc.get(Calendar.YEAR)); ret.append("-"); ret.append(gc.get(Calendar.MONTH) - 1); ret.append("-"); ret.append(gc.get(Calendar.DATE)); ret.append(" "); ret.append(gc.get(Calendar.HOUR)); ret.append(":"); ret.append(gc.get(Calendar.MINUTE)); ret.append(" "); if (gc.get(Calendar.AM_PM) == 0) { ret.append("AM"); } else { ret.append("PM"); } return ret.toString(); } catch (Exception e) { return ""; } }