List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:edu.sjsu.cmpe275.project.util.HtmlPageComposor.java
public static String orderReceipt(Reservation reservation) { //TODO: discount + total fee String bill = ""; int total = 0; SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/YYYY"); Date date = reservation.getCheckinDate(); bill = "<table border='1' style='width:100%'>"; bill += "<tr>"; bill += "<th>Date</th>"; bill += "<th>Room No</th>"; bill += "<th>Base Price</th>"; bill += "<th>Discount(%)</th>"; bill += "<th>Final Fee</th>"; bill += "</tr>"; while (date.before(reservation.getCheckoutDate())) { for (Room room : reservation.getRoomList()) { bill += "<tr>"; bill += "<td>" + sdf.format(date) + "</td>"; bill += "<td>" + room.getRoomNo() + "</td>"; bill += "<td>" + room.getBasePrice() + "</td>"; bill += "<td>" + reservation.getDiscount() + "</td>"; int fee = room.getBasePrice() * (100 - reservation.getDiscount()) / 100; total += fee;/* ww w . j a va2s.c o m*/ bill += "<td>" + fee + "</td>"; bill += "</tr>"; } //increase one day Calendar c = Calendar.getInstance(); c.setTime(date); c.add(Calendar.DATE, 1); date = c.getTime(); } bill += "</table>"; bill += "<h3 align='right'>Total($): " + total + "</h3>"; String page = "<html><body>" + "<h3>Dear " + reservation.getName().getFname() + ",</h3>" + "<h3>Thank you for choosing us serving you! Your room(s) have been checked out.</h3>" + "<h3>Here is the detail of bill:</h3>" + bill + "<h3>Regards,</h3>" + "<h3>CMPE275 Mini Hotel Team</h3>" + "</body></html>"; return page; }
From source file:com.ocs.dynamo.utils.DateUtils.java
/** * Gets the number of the last week of a year * /*from w ww.j av a2 s. c om*/ * @param year * the year * @return */ public static int getLastWeekOfYear(int year) { Date date = createDate("3112" + year); Calendar calendar = Calendar.getInstance(DynamoConstants.DEFAULT_LOCALE); calendar.setTime(date); // it is possible for the last day of a year to actually be part of the // first week of next year. We have to compensate for this int weekNumber = calendar.get(Calendar.WEEK_OF_YEAR); while (weekNumber == 1) { calendar.add(Calendar.DATE, -1); weekNumber = calendar.get(Calendar.WEEK_OF_YEAR); } return weekNumber; }
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 w w w . j a v a 2s.c o 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:fxts.stations.trader.ui.dialogs.ADatePage.java
/** * Returns begining date/*from w ww. j av a2 s. c o m*/ * * @return */ public String getBeginDate() { Calendar instance = Calendar.getInstance(); instance.setTime(mCalendarComboBegin.getDate()); boolean date = instance.get(Calendar.DATE) == Calendar.getInstance().get(Calendar.DATE); boolean month = instance.get(Calendar.MONTH) == Calendar.getInstance().get(Calendar.MONTH); boolean year = instance.get(Calendar.YEAR) == Calendar.getInstance().get(Calendar.YEAR); if (date && month && year) { TradingSessionStatus tss = TradingServerSession.getInstance().getTradingSessionStatus(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone(tss.getFXCMServerTimeZoneName())); String etd = TradingServerSession.getInstance().getParameterValue("END_TRADING_DAY"); String now = sdf.format(new Date()); if (now.compareTo(etd) > 0) { instance.roll(Calendar.DATE, true); } return mDateFormat.format(instance.getTime()); } else { return mDateFormat.format(mCalendarComboBegin.getDate()); } }
From source file:net.duckling.ddl.service.share.impl.ShareFileAccessServiceImpl.java
@Override public boolean isValidRequest(ShareFileAccess instance) { Calendar c = Calendar.getInstance(); c.setTime(instance.getCreateTime()); c.add(Calendar.DATE, instance.getValidOfDays()); return c.getTime().after(new Date()); }
From source file:gov.utah.dts.det.ccl.documents.reporting.reports.AbstractDimensionReport.java
protected Input getEndDateInput() { return new Input(DATE_RANGE_END_KEY, "End Date", DateUtils.truncate(new Date(), Calendar.DATE), Date.class, true, InputDisplayType.DATE); }
From source file:org.openmrs.module.kenyaemr.reporting.builder.patientlist.DecliningCD4Report.java
@Override protected void addColumns(PatientDataSetDefinition dsd) { Concept concept = Dictionary.getConcept(Dictionary.CD4_COUNT); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -180); Date onOrBefore = calendar.getTime(); addStandardColumns(dsd);//www .j av a 2 s. c o m dsd.addColumn("Previous CD4", new ObsForPersonDataDefinition("Previous CD4", TimeQualifier.LAST, concept, onOrBefore, null), "", new DataConverter() { @Override public Class<?> getInputDataType() { return Obs.class; } @Override public Class<?> getDataType() { return Double.class; } @Override public Object convert(Object input) { return ((Obs) input).getValueNumeric(); } }); dsd.addColumn("Current CD4", new ObsForPersonDataDefinition("Current CD4", TimeQualifier.LAST, concept, new Date(), null), "", new DataConverter() { @Override public Class<?> getInputDataType() { return Obs.class; } @Override public Class<?> getDataType() { return Double.class; } @Override public Object convert(Object input) { return ((Obs) input).getValueNumeric(); } }); addViewColumn(dsd); }
From source file:com.cemeterylistingswebtest.test.services.SubscriptionServiceTest.java
@Test public void createSub() { repo = ctx.getBean(SubscriberRepository.class); adserv = ctx.getBean(AdminRegisterSubscriberService.class); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2014); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 9); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(2).build(); //userRepo.save(user); //userRoleID = user.getUserRoleID(); Subscriber newSub = new Subscriber.Builder().setEmail("bull@horse.com").setFirstName("red") .setSurname("bull").setPwd("wings").setUsername("redBull").setSubscriptionDate(javaSqlDate) .setUserRoleID(user).build(); repo.save(newSub);// w w w .j a va 2 s . c om id = newSub.getSubscriberID(); Assert.assertFalse(repo.findAll().isEmpty()); }
From source file:com.citrix.cpbm.custom.reports.CustomerReport.java
@Override protected Statement getStatement(Connection connection) throws SQLException { String type = (String) report.getParams().get("type"); // Filter Section Coming from Params StringBuilder filter = new StringBuilder(); if (type.equalsIgnoreCase("MONTHLY")) { filter.append(" AND DATE_FORMAT(t.created_at, '%Y%c') = '") .append(report.getParams().get(CustomReportsConstants.YEAR)) .append(report.getParams().get(CustomReportsConstants.MONTH)).append("'"); } else if (type.equalsIgnoreCase("DAILY")) { Calendar cal = (Calendar) report.getParams().get("date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); cal.add(Calendar.DATE, -1); // Decreasing by one day as it should pick up yesterday's data for today's run filter.append(" AND (DATE(t.created_at) = '").append(sdf.format(cal.getTime())) .append("' OR (tch.action = '"); filter.append(Action.CONVERTED.name()).append("' AND DATE(tch.created_at) = '") .append(sdf.format(cal.getTime())).append("')) "); cal.add(Calendar.DATE, 1); // Put the run date back }//w w w.j a v a 2 s. co m // Account Type Details Filter if coming from params AccountType accountType = (AccountType) this.report.getParams().get("account_type"); if (accountType != null) { filter.append(" AND t.account_type = ").append(accountType.getId()); } // LastRecord Id Section If coming from params String lastRecordId = (String) this.report.getParams().get("last_record_id"); if (StringUtils.isNotEmpty(lastRecordId)) { filter.append(" AND t.id > ").append(lastRecordId); } // Limit Section If coming from Params String fetchSize = (String) this.report.getParams().get("limit"); String limit = ""; if (StringUtils.isNotEmpty(fetchSize)) { limit = " ORDER BY t.id LIMIT " + fetchSize; } StringBuffer query = new StringBuffer(); query.append("SELECT t.id AS UniqueId, t.account_id as AccountNum, "); query.append(" t.name AS name, "); query.append(" atype.payment_modes AS PaymentMode, "); query.append(" a.postal_code AS ZipCode1, "); query.append(" a.street1 AS Address1 "); query.append("FROM tenants t LEFT JOIN tenant_change_history tch ON tch.tenant_id = t.id"); query.append(" AND tch.action = '").append(Action.CONVERTED.name()) .append("' AND tch.old_account_type IN (SELECT id FROM account_types WHERE trial = 1), "); query.append(" addresses a, account_types atype "); query.append("WHERE t.address_id=a.id AND atype.id = t.account_type "); query.append(filter); query.append(limit); logger.debug("About to fire a query: " + query.toString()); return connection.prepareStatement(query.toString()); }
From source file:gov.nih.nci.cabig.caaers.utils.DateUtils.java
/** * This is a convenient method to get yesterday date * @return//from w w w . j a v a 2 s . co m */ public static Date yesterday() { Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, -1); Date d = c.getTime(); d.setHours(0); d.setMinutes(0); return d; }