List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:org.bungeni.editor.system.ConfigGeneratorError.java
private void initErrorFile() { Element rootElement = new Element("errors"); Date currentDate = GregorianCalendar.getInstance().getTime(); rootElement.setAttribute("date", currentDate.toString()); docError = new Document(rootElement); saveFile();//from ww w . ja v a 2 s . co m }
From source file:com.cegeka.GethBean.java
public void sendMessage() throws Exception { if (!enableSender) { return;//from w w w . j a v a 2 s . c om } Date now = new Date(); System.out.println("[" + now.toString() + "]Sending to all!"); ProducerTemplate template = camelContext.createProducerTemplate(); template.sendBodyAndHeader("jms:topic:eth", ExchangePattern.InOnly, new Message("Hey there, little buddy!"), "uuid", gethRoute.getUUID()); template.stop(); }
From source file:co.nubetech.apache.hadoop.DateSplitter.java
/** * Given a Date 'd', format it as a string for use in a SQL date comparison * operation.//from w w w .j ava2 s . co m * * @param d * the date to format. * @return the string representing this date in SQL with any appropriate * quotation characters, etc. */ protected String dateToString(Date d) { return "'" + d.toString() + "'"; }
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; }/* w w w. j a v a 2 s .c om*/ 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.com.controller.ProductController.java
@RequestMapping(value = "/repProduct", method = RequestMethod.GET) public void productReport(Model m, HttpServletResponse response, HttpServletRequest request, OutputStream outputStream) throws Exception { String name = "ProductReport-"; Date d = new Date(); name = name + d.toString() + ".pdf"; response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=" + name); Rectangle pagesize = new Rectangle(216f, 720f); Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, outputStream); document.open();/*from w ww. j a va2 s. com*/ document.addTitle("PRODUCT DETAILSA REPORT"); document.add(new Paragraph("PRODUCT DETAILSA REPORT ", FontFactory.getFont(FontFactory.HELVETICA, 28, BaseColor.CYAN))); document.add(new Paragraph("DATE: " + new Date())); document.add(new Paragraph("-------------------------------------------------------- ")); document.add(new Paragraph(" ")); ProductDaoImpl pdi = new ProductDaoImpl(); PdfPTable table = new PdfPTable(4); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell("ID"); table.addCell("TITLE"); table.addCell("PUBLISHER"); table.addCell("PRICE"); ArrayList<ProductTable> list = pdi.getAllProduct(); for (ProductTable u : list) { table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(u.getPid().toString()); table.getDefaultCell().setBackgroundColor(BaseColor.GRAY); table.addCell(u.getPname()); table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(u.getPublisher()); table.getDefaultCell().setBackgroundColor(BaseColor.GRAY); table.addCell(u.getSprice().toString()); } document.add(table); document.close(); }
From source file:com.amazon.s3.S3ParserTest.java
@SuppressWarnings("unchecked") @Test(enabled = false)/*from ww w . ja v a 2 s . c o m*/ public void testAmazonCanParseListAllMyBuckets() throws IOException { ListAllMyBucketsResponse response = runAmazonParseListAllMyBuckets(); List<Bucket> buckets = response.entries; Bucket bucket1 = (Bucket) buckets.get(0); assert bucket1.name.equals("adrianjbosstest"); Date expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z").toDate(); Date date1 = bucket1.creationDate; assert date1.toString().equals(expectedDate1.toString()); Bucket bucket2 = (Bucket) buckets.get(1); assert bucket2.name.equals("adrianjbosstest2"); Date expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z").toDate(); Date date2 = bucket2.creationDate; assert date2.toString().equals(expectedDate2.toString()); assert buckets.size() == 2; }
From source file:org.mendix.eclipse.builder.Mod4jEclipseWorkflowRunner.java
/** * General Mod4j workflow runner. /*from w w w . j a va 2s. co m*/ * * @param wfFile * absolute path string of the workflow file to execute * @param properties * Map containing the properties for <code>wfFile</code>. * @throws Mod4jWorkflowException */ public void runWorkflow(final String wfFile, final Map<String, String> properties) throws Mod4jEclipseWorkflowException { Map<String, Object> slotContents = new HashMap<String, Object>(); WorkflowRunner runner = new WorkflowRunner(); String propertiesListing = ""; for (Map.Entry<String, String> prop : properties.entrySet()) { propertiesListing += "\t\t" + prop.toString() + "\n"; } logger.info("Running workflow [" + wfFile + "] with properties : \n" + propertiesListing); Date date = new Date(System.currentTimeMillis()); System.err.println("03 ================== " + date.toString() + ": workflow [" + wfFile + "]"); ResourceLoader loader = ResourceLoaderFactory.getCurrentThreadResourceLoader(); System.err.println("Classloader: " + (loader == null ? "NULL" : loader.toString())); if (loader == null) { CachingResourceLoaderImpl crl = new CachingResourceLoaderImpl( new OsgiResourceLoader("org.mendix.common", FileTrack.class.getClassLoader())); ResourceLoaderFactory.setCurrentThreadResourceLoader(crl); } date = new Date(System.currentTimeMillis()); System.err.println("04 ================== " + date.toString() + ": workflow [" + wfFile + "]"); if (!runner.run(wfFile, new NullProgressMonitor(), properties, slotContents)) { logger.error("--------------------------------------------------------------------------------------"); logger.error("------- ERROR(S) detected while running workflow : [" + wfFile + "] "); logger.error("------- See logging above for more details."); logger.error("--------------------------------------------------------------------------------------"); throw new Mod4jEclipseWorkflowException("ERROR(S) detected while running workflow :" + wfFile); } date = new Date(System.currentTimeMillis()); System.err.println("05 ================== " + date.toString() + ": workflow [" + wfFile + "]"); logger.info("--------------------------------------------------------------------------"); logger.info("-------- Workflow SUCCESSFUL! "); logger.info("--------------------------------------------------------------------------"); }
From source file:org.sbq.batch.tasks.LongRunningBatchTask.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { Date scheduledFireTime = (Date) chunkContext.getStepContext().getJobParameters().get("scheduledFireTime"); System.out.println(">>>> LongRunningBatchTask.execute( " + scheduledFireTime.toString() + " )"); int i = 0;// w ww.j ava 2 s . co m while (i < 600) // we don't pay attention if we are interrupted { i++; try { Thread.sleep(1000L); } catch (InterruptedException e) { Thread.interrupted(); } } return RepeatStatus.FINISHED; }
From source file:JSONRequesterWithParser.java
public void ParseAndSaveJSONResponse(String response) { try {/*from w w w .j av a2 s . com*/ JSONObject jsonData = new JSONObject(response); JSONObject rec = jsonData.getJSONObject("rec"); //System.out.println(rec.toString()); JSONObject veh = rec.getJSONObject("vehicles"); //System.out.println(veh.toString()); JSONArray vehicles = (JSONArray) veh.get("vehicles"); //System.out.println(vehcles); System.out.println("No of vehicles data found :" + vehicles.length()); List<String> vehicleList = new ArrayList<>(); for (int item = 0; item < vehicles.length(); item++) { //properties for single vehicle JSONObject vehData = vehicles.getJSONObject(item); JSONObject position = vehData.getJSONObject("position"); VehicleData vehicle = new VehicleData(); Date currentDateTime = new Date(); vehicle.dateTime = currentDateTime.toString(); vehicle.address = position.getString("address"); vehicle.latitude = position.getString("latitude"); vehicle.longitude = position.getString("longitude"); vehicle.carName = vehData.getString("carName"); vehicle.licensePlate = vehData.getString("licensePlate"); vehicle.group = vehData.getString("group"); String filePath = FindFilePath(vehicle.address); Save(vehicle, filePath); } } catch (Exception e) { e.printStackTrace(); } }
From source file:assignment.HTTPResponse.java
public void serve(HTTPRequest httpRequest, OutputStream outputStream, Socket socket) throws IOException, ParseException, InterruptedException { PrintWriter pw = new PrintWriter(outputStream, true); JSONObject obj = new JSONObject(); if (httpRequest.getHttpMethod().equals("GET")) { String[] url = (httpRequest.getResourceURI()).split("\\?"); if (url[0].equals("/request")) { String ar1[] = url[1].split("&"); String[] name1 = ar1[0].split("="); String connId = name1[1]; String[] name2 = ar1[1].split("="); int timeout = Integer.parseInt(name2[1]); input[i][0] = connId;//from w w w .j a v a 2 s.co m Date startTime = new Date(); Date parsedDate = df.parse(startTime.toString()); Date endTime = new Date(parsedDate.getTime() + (1 * timeout)); input[i][1] = startTime.toString(); input[i][2] = endTime.toString(); i++; obj.put("status", "ok"); try { Thread.currentThread().sleep(timeout); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } pw.println(obj); } else if (url[0].equals("/serverStatus")) { Date now = new Date(); long newDateTime = df.parse((new Date()).toString()).getTime(); String result = ""; JSONArray ja = new JSONArray(); for (int j = 0; j < input.length; j++) { if (input[j][0] != null) { Date end = df.parse(input[j][2]); if (end.compareTo(now) > 0) { long endDateTime = (df.parse(input[j][2])).getTime(); long diff = ((endDateTime - newDateTime) / 1000); JSONObject obj1 = new JSONObject(); obj1.put(input[j][0], diff); result += obj1; } } } pw.println(result); } else { pw.println("Request not supported."); } } else if ((httpRequest.getHttpMethod().equals("PUT")) || (httpRequest.getHttpMethod().equals("POST"))) { if (httpRequest.getResourceURI().equals("/kill")) { boolean found = false; Date now = new Date(); for (int j = 0; j < input.length; j++) { if (input[j][0] != null && input[j][0].equals(httpRequest.getBody())) { Date end = df.parse(input[j][2]); if (end.compareTo(now) > 0) { input[j][2] = now.toString(); found = true; } } } if (found) { obj.put("status", "killed"); } else { obj.put("status", "Invalid connId " + httpRequest.getBody()); } System.out.println(obj); pw.println(obj); } else { pw.println("Request not supported."); } } socket.close(); }