List of usage examples for java.util GregorianCalendar GregorianCalendar
public GregorianCalendar()
GregorianCalendar
using the current time in the default time zone with the default Locale.Category#FORMAT FORMAT locale. From source file:mx.clickfactura.util.TipoCambioUtil.java
public String getTipoCambio(String fecha) throws CustomBadRequestException, CustomNotFoundException, Exception { Pattern pattern = Pattern.compile("^\\d{4}\\-\\d{2}\\-\\d{2}$"); Matcher matcher = null;// w w w. j a va2s .c o m matcher = pattern.matcher(fecha.trim()); if (!matcher.matches()) { throw new CustomBadRequestException("Fecha invalida, el formato debe ser: yyyy-MM-dd"); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = new GregorianCalendar(); cal.setTime(sdf.parse(fecha)); String dia = (cal.get(Calendar.DATE) < 10) ? "0" + cal.get(Calendar.DATE) : cal.get(Calendar.DATE) + ""; String mes = ((cal.get(Calendar.MONTH) + 1) < 10) ? "0" + (cal.get(Calendar.MONTH) + 1) : (cal.get(Calendar.MONTH) + 1) + ""; String anio = cal.get(Calendar.YEAR) + ""; String fechaInicial = dia + "%2F" + mes + "%2F" + anio; CloseableHttpClient client = HttpClients.createDefault(); CookieStore cookies = new BasicCookieStore(); String[] fechaSeparada = fecha.split("-"); HttpGet get = new HttpGet("http://www.dof.gob.mx/indicadores_detalle.php?cod_tipo_indicador=158&dfecha=" + fechaInicial + "&hfecha=" + fechaInicial); HttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookies); CloseableHttpResponse response = client.execute(get, httpContext); //System.out.println(response.toString()); //System.out.println(response.getStatusLine()); //System.out.println(response.getEntity().getContentLength()); InputStream in = response.getEntity().getContent(); Header encoding = response.getEntity().getContentEncoding(); String body = IOUtils.toString(in, "UTF-8"); //System.out.println(body); Document doc = Jsoup.parse(body, "UTF-8"); doc = doc.normalise(); //System.out.println(doc.toString()); Elements e = doc.select("table"); Iterator iterator = e.iterator(); pattern = Pattern.compile("^\\d{2}\\.\\d{6}$"); matcher = null; String tipoCambio = null; while (iterator.hasNext()) { Element xd = (Element) iterator.next(); if (xd.getElementsByClass("txt").hasAttr("height")) { if (xd.getElementsByClass("txt").text().split(" ").length == 6) { String cambio = xd.getElementsByClass("txt").text().split(" ")[5]; matcher = pattern.matcher(cambio.trim()); if (matcher.matches()) { tipoCambio = cambio; //System.out.println(tipoCambio); break; } } } } client.close(); response.close(); if (tipoCambio == null || tipoCambio.isEmpty()) { throw new CustomNotFoundException("No hay un tipo de cambio para el da: " + fecha); } return tipoCambio; }
From source file:models.MilestoneTest.java
@Test public void findById() throws Exception { // Given/*from ww w. j a v a 2s.co m*/ // When Milestone firstMilestone = Milestone.findById(1l); // Then assertThat(firstMilestone.title).isEqualTo("v.0.1"); assertThat(firstMilestone.getContents()).isEqualTo("nFORGE ."); Calendar expactDueDate = new GregorianCalendar(); expactDueDate.set(2012, Calendar.JULY, 12, 23, 59, 59); // 2012-07-12 Calendar dueDate = new GregorianCalendar(); dueDate.setTime(firstMilestone.dueDate); assertThat(expactDueDate.get(Calendar.YEAR)).isEqualTo(dueDate.get(Calendar.YEAR)); assertThat(expactDueDate.get(Calendar.MONTH)).isEqualTo(dueDate.get(Calendar.MONTH)); assertThat(expactDueDate.get(Calendar.DAY_OF_MONTH)).isEqualTo(dueDate.get(Calendar.DAY_OF_MONTH)); assertThat(firstMilestone.getNumClosedIssues()).isEqualTo(2); assertThat(firstMilestone.getNumOpenIssues()).isEqualTo(2); assertThat(firstMilestone.getNumTotalIssues()).isEqualTo(4); assertThat(firstMilestone.project).isEqualTo(Project.find.byId(1l)); assertThat(firstMilestone.getCompletionRate()).isEqualTo(50); }
From source file:iddb.web.viewbean.PenaltyViewBean.java
public Date getExpires() { Calendar calendar = new GregorianCalendar(); calendar.setTime(this.created); calendar.add(Calendar.MINUTE, this.getDuration().intValue()); return calendar.getTime(); }
From source file:com.baidu.rigel.biplatform.ac.util.TimeRangeDetail.java
/** * ?// www. j av a2s. co m * @param date * @return ?? */ public static String toTime(Date date) { if (date == null) { date = new GregorianCalendar().getTime(); } SimpleDateFormat format = initDateFormat(); return format.format(date); }
From source file:gov.nih.nci.cabig.caaers.domain.DateTimeValue.java
/** * Instantiates a new date value.//from ww w. j ava2 s .c o m * * @param date the date */ public DateTimeValue(Date date) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date); this.day = gc.get(Calendar.DAY_OF_MONTH); this.month = gc.get(Calendar.MONTH) + 1; this.year = gc.get(Calendar.YEAR); }
From source file:io.getlime.security.powerauth.soap.spring.client.PowerAuthServiceClient.java
/** * Convert date to XMLGregorianCalendar//from w w w. j av a 2 s . c o m * @param date Date to be converted. * @return A new instance of {@link XMLGregorianCalendar}. * @throws DatatypeConfigurationException */ private XMLGregorianCalendar calendarWithDate(Date date) { try { GregorianCalendar c = new GregorianCalendar(); c.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(c); } catch (DatatypeConfigurationException e) { // Unless there is a terrible configuration error, this should not happen e.printStackTrace(); } return null; }
From source file:com.vangent.hieos.logbrowser.util.TableModel.java
public TableModel(String sqlRequest, Map fieldsAndFormats, Connection c) throws SQLException { this.fieldsAndFormats = fieldsAndFormats; ResultSet statementResult;//www .j a v a 2 s .c o m log.debug("TABLE_MODEL_SYSLOG: database connection created\n"); Statement statement = c.createStatement(); log.debug("TABLE_MODEL_SYSLOG: statement created\n"); statementResult = statement.executeQuery(sqlRequest); log.debug("TABLE_MODEL_SYSLOG: Query executed\n"); log.debug("<--" + new GregorianCalendar().getTime() + " TableModel close Database \n"); ResultSetMetaData metaData = statementResult.getMetaData(); int columnCount = metaData.getColumnCount(); dataVector = new Vector<Vector<Object>>(); headerVector = new Vector<String>(); log.debug("TABLE_MODEL_SYSLOG: colomn count : " + columnCount + "\n"); log.debug("TABLE_MODEL_SYSLOG: Table--------------------------------------"); for (int i = 0; i < columnCount; i++) { headerVector.add(metaData.getColumnName((i + 1))); log.debug(metaData.getColumnName((i + 1)) + "\t"); } while (statementResult.next()) { Vector<Object> tmp = new Vector<Object>(columnCount); for (int j = 0; j < columnCount; j++) { String columnName = getColumnName(j); Object columnData = statementResult.getObject(columnName); columnData = getFormattedData(columnName, columnData); tmp.add(columnData); log.debug(columnData + "\t"); } log.debug("\n"); dataVector.add(tmp); } }
From source file:ezbake.data.elastic.test.TestUtils.java
public static Facet generateDateBucketFacet() { final SimpleDateFormat dtg = new SimpleDateFormat("ddHHmm'Z' MM yy"); final Calendar calendar = new GregorianCalendar(); final Facet ssrDateFacet = new Facet(); final RangeFacet dateRangeFacet = new RangeFacet(); final BaseFacetValue dateField = new BaseFacetValue(); dateField.setFacetField("visit"); dateRangeFacet.setField(dateField);// w ww. ja v a 2 s . c om final FacetRange last24 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last24time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last24.setFrom(dtg.format(last24time)); dateRangeFacet.addToRanges(last24); final FacetRange last48 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last48time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last48.setFrom(dtg.format(last48time)); dateRangeFacet.addToRanges(last48); final FacetRange last72 = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -1); last72time = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last72.setFrom(dtg.format(last72time)); dateRangeFacet.addToRanges(last72); final FacetRange lastWeek = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -4); lastWeekTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); lastWeek.setFrom(dtg.format(lastWeekTime)); dateRangeFacet.addToRanges(lastWeek); final FacetRange last30Days = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -23); last30DaysTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last30Days.setFrom(dtg.format(last30DaysTime)); dateRangeFacet.addToRanges(last30Days); final FacetRange last90Days = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -60); last90DaysTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); last90Days.setFrom(dtg.format(last90DaysTime)); dateRangeFacet.addToRanges(last90Days); final FacetRange lastYear = new FacetRange(RangeType.DATE); calendar.add(Calendar.DAY_OF_YEAR, -275); lastYearTime = DateUtils.round(calendar, Calendar.HOUR).getTimeInMillis(); lastYear.setFrom(dtg.format(lastYearTime)); dateRangeFacet.addToRanges(lastYear); final FacetRequest dateRequest = new FacetRequest(); dateRequest.setRangeFacet(dateRangeFacet); ssrDateFacet.setLabel("Report Date"); ssrDateFacet.setFacet(dateRequest); return ssrDateFacet; }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Increments the date by one day// w w w.ja va2 s. c o m * @param date - date to be incremented */ public static void incDateByDay(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, 1); date.setTime(cal.getTimeInMillis()); }