List of usage examples for java.util Date setYear
@Deprecated public void setYear(int year)
From source file:FillTest.java
public static void main(String args[]) { int array[] = new int[10]; Arrays.fill(array, 100);/*from w w w . j a v a 2 s .c om*/ for (int i = 0, n = array.length; i < n; i++) { System.out.println(array[i]); } System.out.println(); Arrays.fill(array, 3, 6, 50); for (int i = 0, n = array.length; i < n; i++) { System.out.println(array[i]); } byte array2[] = new byte[10]; Arrays.fill(array2, (byte) 4); System.out.println(); Date array3[] = new Date[10]; Date anObject = new Date(); Arrays.fill(array3, "Help"); anObject.setYear(102); for (int i = 0, n = array3.length; i < n; i++) { System.out.println(array3[i]); } }
From source file:Main.java
public static String calculateAge(Context context, String date) { final String FACEBOOK = "MM/dd/yyyy"; try {//w w w .j a v a2 s .c o m SimpleDateFormat sf = new SimpleDateFormat(FACEBOOK, Locale.ENGLISH); sf.setLenient(true); Date birthDate = sf.parse(date); Date now = new Date(); int age = now.getYear() - birthDate.getYear(); birthDate.setHours(0); birthDate.setMinutes(0); birthDate.setSeconds(0); birthDate.setYear(now.getYear()); if (birthDate.after(now)) { age -= 1; } return Integer.toString(age); } catch (Exception e) { Log.d("DEBUG", "exception in getTwitterDate:"); e.printStackTrace(); return "Unknown"; } }
From source file:ucd.denver.com.diskussioner.entityParser.parseToJson.java
public static List<Discussion> parseToDiscussion(String content) { try {/*from ww w . ja v a 2 s . c o m*/ JSONArray ja = new JSONArray(content); List<Discussion> disList = new ArrayList<>(); for (int i = 0; i < ja.length(); i++) { JSONObject jo = ja.getJSONObject(i); Discussion d = new Discussion(); d.setId(jo.getInt("id")); String da = jo.getString("started_date").toString(); System.out.println(da); Date statedDate = new Date(); String[] dateSplit = da.split("-"); statedDate.setYear(Integer.parseInt(dateSplit[0]) - 1900); statedDate.setMonth(Integer.parseInt(dateSplit[1])); statedDate.setDate(Integer.parseInt(dateSplit[2])); System.out.println(statedDate); System.out.println("stated Date" + statedDate); d.setStartedDate(statedDate); d.setTopic(jo.getString("topic")); User u = new User(); u.setEmail(jo.getString("started_user")); d.setStartedUser(u); disList.add(d); } System.out.println("dis List size:::" + disList.size()); return disList; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:foam.zizim.android.Util.java
public static void findDeletedIncidents(Context context) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new java.util.Date(); date.setYear(date.getYear() - 1); StringBuilder datetime = new StringBuilder(dateFormat.format(date)); String sinceDate = datetime.toString(); //request all deleted incidents from the last year try {//ww w . j av a2 s.c o m if (Incidents.getDeletedIncidentsFromWeb(sinceDate)) { List<IncidentsData> deletedIncidents = HandleXml .processIncidentsXml(BoskoiService.incidentsResponse, context); BoskoiApplication.mDb.deleteIncidents(deletedIncidents); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.taobao.ad.jpa.test.ReportJobRtTest.java
@SuppressWarnings("deprecation") @Test/*from ww w . j a v a2 s . c o m*/ public void testGet() { Date d = new Date(); d.setYear(d.getYear() - 1); Assert.assertNotNull(reportJobRtBO.getAverageRt(d, new Date())); System.out.println(reportJobRtBO.getAverageRt(d, new Date())); }
From source file:org.apache.hadoop.hive.ql.udf.UDFNextDay.java
public String evaluate(String date, Integer day) { if (date == null || day == null) { return null; }/* ww w. j av a 2 s.com*/ if (day < 1 || day > 7) { return null; } Pattern pattern = Pattern.compile("([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])[\\s\\S]*(\\..*)?$"); Matcher matcher = pattern.matcher(date); if (!matcher.matches()) { return null; } int year = Integer.valueOf(matcher.group(1)); int month = Integer.valueOf(matcher.group(2)); int dd = Integer.valueOf(matcher.group(3)); Date ret = new Date(); ret.setYear(year - 1900); ret.setMonth(month - 1); ret.setDate(dd); ret.setHours(0); ret.setMinutes(0); ret.setSeconds(0); Calendar curr = Calendar.getInstance(); curr.setTime(ret); int curr_week = curr.get(Calendar.DAY_OF_WEEK); int offset = 7 + (day - curr_week); curr.add(Calendar.DAY_OF_WEEK, offset); Date newDate = curr.getTime(); System.out.println("newDate:" + newDate.toString()); year = curr.get(Calendar.YEAR); month = curr.get(Calendar.MONTH) + 1; dd = curr.get(Calendar.DAY_OF_MONTH); System.out.println("curr.get(Calendar.MONTH):" + curr.get(Calendar.MONTH)); return String.format("%04d-%02d-%02d", year, month, dd); }
From source file:org.eclipse.flux.cloudfoundry.deployment.service.CfDeploymentService.java
private CloudFoundryClientDelegate getCfClient(JSONObject req) throws Exception { DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(req.getString(CF_TOKEN)); //We must set expiration or CF client will try to refresh it and throw an NPE because it has no // refresh token. See https://github.com/cloudfoundry/cf-java-client/issues/214 Date nextYear = new Date(); nextYear.setYear(nextYear.getYear() + 1); token.setExpiration(nextYear);/* ww w . ja v a 2s .c o m*/ return new CloudFoundryClientDelegate(req.getString(USERNAME), token, new URI(req.getString(CF_CONTROLLER_URL)).toURL(), getStringMaybe(req, CF_SPACE), flux, appLogs); }
From source file:com.wonders.stpt.metroIndicator.service.impl.MetroProductionServiceImpl.java
@SuppressWarnings("deprecation") public MetroProduction findSamePeriodLastYear(String now, String line) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List<MetroProduction> dataList = metroProductionDao.findProductionWithData(now, line); if (dataList != null && dataList.size() != 0) { now = dataList.get(0).getIndicatorDate(); }/*from ww w.j a v a 2s .c o m*/ try { Date lastyear = sdf.parse(now); // lastyear.setYear(lastyear.getYear() - 1); List<MetroProduction> list = metroProductionDao.findSamePeriodLastYear(sdf.format(lastyear), line); if (list != null && list.size() > 0) return list.get(0); return null; } catch (ParseException e) { return null; } }
From source file:org.openmrs.module.vcttrac.web.view.chart.EvolutionOfClientRegisteredPerDay.java
/** * @see org.openmrs.module.vcttrac.web.view.chart.AbstractChartView#createChart(java.util.Map, * javax.servlet.http.HttpServletRequest) *//*from ww w . ja v a 2 s. c o m*/ @Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { String categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.yAxis.days", null); String valueAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.xAxis.numberofclient", null); int numberOfDays = 7, dayFormat = 1; if (request.getParameter("graphCategory") != null) { if (request.getParameter("graphCategory").trim().compareTo("2") == 0) { Date d = new Date(); d.setDate(1); d.setMonth((new Date()).getMonth()); d.setYear((new Date()).getYear()); numberOfDays = (int) (((new Date()).getTime() - d.getTime()) / VCTTracConstant.ONE_DAY_IN_MILLISECONDS); categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.month." + ((new Date()).getMonth() + 1), null); dayFormat = 2; } } String title = ""; title = VCTTracUtil.getMessage("vcttrac.graph.evolution.client.received", null); JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, createDataset(numberOfDays, dayFormat), // data PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); return chart; }
From source file:org.epics.archiverappliance.etl.ConsolidateETLJobsForOnePVTest.java
@SuppressWarnings("deprecation") private void Consolidate() throws AlreadyRegisteredException, IOException, InterruptedException { PVTypeInfo typeInfo = new PVTypeInfo(pvName, ArchDBRTypes.DBR_SCALAR_DOUBLE, true, 1); String[] dataStores = new String[] { storageplugin1.getURLRepresentation(), storageplugin2.getURLRepresentation(), storageplugin3.getURLRepresentation() }; typeInfo.setDataStores(dataStores);/*ww w . j av a 2 s. c om*/ configService.updateTypeInfoForPV(pvName, typeInfo); configService.registerPVToAppliance(pvName, configService.getMyApplianceInfo()); configService.getETLLookup().manualControlForUnitTests(); //generate datas of 10 days PB file 2012_01_01.pb to 2012_01_10.pb int dayCount = 10; for (int day = 0; day < dayCount; day++) { logger.debug("Generating data for day " + 1); int startofdayinseconds = day * 24 * 60 * 60; int runsperday = 12; int eventsperrun = 24 * 60 * 60 / runsperday; for (int currentrun = 0; currentrun < runsperday; currentrun++) { try (BasicContext context = new BasicContext()) { logger.debug("Generating data for run " + currentrun); YearSecondTimestamp yts = new YearSecondTimestamp(currentYear, (day + 1) * 24 * 60 * 60, 0); Timestamp etlTime = TimeUtils.convertFromYearSecondTimestamp(yts); logger.debug("Running ETL as if it were " + TimeUtils.convertToHumanReadableString(etlTime)); ETLExecutor.runETLs(configService, etlTime); ArrayListEventStream testData = new ArrayListEventStream(eventsperrun, new RemotableEventStreamDesc(type, pvName, currentYear)); for (int secondsinrun = 0; secondsinrun < eventsperrun; secondsinrun++) { testData.add( new SimulationEvent(startofdayinseconds + currentrun * eventsperrun + secondsinrun, currentYear, type, new ScalarValue<Double>((double) secondsinrun))); } storageplugin1.appendData(context, pvName, testData); } // Sleep for a couple of seconds so that the modification times are different. Thread.sleep(2 * 1000); } } // end for File shortTermFIle = new File(shortTermFolderName); File mediumTermFIle = new File(mediumTermFolderName); //File longTermFIle=new File(longTermFolderName); String[] filesShortTerm = shortTermFIle.list(); String[] filesMediumTerm = mediumTermFIle.list(); assertTrue("there should be PB files int short term storage but there is no ", filesShortTerm.length != 0); assertTrue("there should be PB files int medium term storage but there is no ", filesMediumTerm.length != 0); //ArchUnitTestConsolidateETLJobsForOnePVTest:_pb.zip File zipFileOflongTermFile = new File(longTermFolderName + "/" + pvName + ":_pb.zip"); assertTrue(longTermFolderName + "/" + pvName + ":_pb.zip shoule exist but it doesn't", zipFileOflongTermFile.exists()); ZipFile lastZipFile1 = new ZipFile(zipFileOflongTermFile); Enumeration<ZipArchiveEntry> enumeration1 = lastZipFile1.getEntries(); int ss = 0; while (enumeration1.hasMoreElements()) { enumeration1.nextElement(); ss++; } assertTrue( "the zip file of " + longTermFolderName + "/" + pvName + ":_pb.zip should contain pb files less than " + dayCount + ",but the number is " + ss, ss < dayCount); // consolidate String storageName = "LTS"; Timestamp oneYearLaterTimeStamp = TimeUtils .convertFromEpochSeconds(TimeUtils.getCurrentEpochSeconds() + 365 * 24 * 60 * 60, 0); // The ConfigServiceForTests automatically adds a ETL Job for each PV. For consolidate, we need to have "paused" the PV; we fake this by deleting the jobs. configService.getETLLookup().deleteETLJobs(pvName); ETLExecutor.runPvETLsBeforeOneStorage(configService, oneYearLaterTimeStamp, pvName, storageName); // make sure there are no pb files in short term storage , medium term storage and all files in long term storage Thread.sleep(4000); String[] filesShortTerm2 = shortTermFIle.list(); String[] filesMediumTerm2 = mediumTermFIle.list(); assertTrue("there should be no files int short term storage but there are still " + filesShortTerm2.length + "PB files", filesShortTerm2.length == 0); assertTrue("there should be no files int medium term storage but there are still " + filesMediumTerm2.length + "PB files", filesMediumTerm2.length == 0); //ArchUnitTestConsolidateETLJobsForOnePVTest:_pb.zip File zipFileOflongTermFile2 = new File(longTermFolderName + "/" + pvName + ":_pb.zip"); assertTrue(longTermFolderName + "/" + pvName + ":_pb.zip shoule exist but it doesn't", zipFileOflongTermFile2.exists()); ZipFile lastZipFile = new ZipFile(zipFileOflongTermFile2); Enumeration<ZipArchiveEntry> enumeration = lastZipFile.getEntries(); ZipEntry zipEntry = null; HashMap<String, String> fileNameMap = new HashMap<String, String>(); while (enumeration.hasMoreElements()) { zipEntry = (ZipEntry) enumeration.nextElement(); String fileNameTemp = zipEntry.getName(); logger.info("fileName1=" + fileNameTemp); int indexPB = fileNameTemp.indexOf(".pb"); int indexDate = indexPB - 5; String dateFileName = fileNameTemp.substring(indexDate, indexPB); fileNameMap.put(dateFileName, dateFileName); //System.out.println("fileName="+dateFileName); logger.info("fileName=" + dateFileName); } assertTrue("The number of files should be " + dayCount + ", acutuallly, it is " + fileNameMap.size(), fileNameMap.size() == dayCount); Date beinningDate = new Date(); beinningDate.setYear(currentYear - 1); beinningDate.setMonth(11); beinningDate.setDate(31); logger.info("currentYear=" + currentYear); logger.info("beinningDate=" + beinningDate); Calendar calendarBeingining = Calendar.getInstance(); calendarBeingining.setTime(beinningDate); SimpleDateFormat df = new SimpleDateFormat("MM_dd"); for (int m = 0; m < dayCount; m++) { calendarBeingining.add(Calendar.DAY_OF_MONTH, 1); String fileNameTemp1 = df.format(calendarBeingining.getTime()); logger.info("fileNameTemp1=" + fileNameTemp1); assertTrue("the file whose name is like " + pvName + ":" + currentYear + "_" + fileNameTemp1 + ".pb should exist,but it doesn't", fileNameMap.get(fileNameTemp1) != null); } }