List of usage examples for java.util Date getHours
@Deprecated public int getHours()
From source file:pa_SymposiumPlanner.BRF2011PanelChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try {/*from w ww. j a va2 s . c om*/ address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } try { System.out.println("Panel Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); // BackwardReasoner br = new BackwardReasoner(); // Iterator solit =null; // DefiniteClause dc = null; // SymbolTable.reset(); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) { date = "" + year + month + day3; } else { date = "" + year + "0" + month + day3; } date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }
From source file:pa_SymposiumPlanner.ECAI2012LiaisonChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from w w w. j a v a 2 s . c om*/ address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { System.out.println("Liaison Chair Servlet 123"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); // BackwardReasoner br = new BackwardReasoner(); // Iterator solit =null; // DefiniteClause dc = null; // SymbolTable.reset(); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) date = "" + year + month + day3; else date = "" + year + "0" + month + day3; date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; System.out.println("1"); while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } System.out.println("2"); MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }
From source file:pa_SymposiumPlanner.RuleML2009PanelChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w .j a v a 2 s . c o m address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { System.out.println("Panel Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); // BackwardReasoner br = new BackwardReasoner(); // Iterator solit =null; // DefiniteClause dc = null; // SymbolTable.reset(); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) date = "" + year + month + day3; else date = "" + year + "0" + month + day3; date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }
From source file:org.openmrs.module.kenyaemr.fragment.controller.NextAppointmentCountFragmentController.java
public JSONObject saveAppointment(@RequestParam("patient") Patient patient, @RequestParam("date") String date, UiUtils ui) {/* ww w . j a va 2s . com*/ Visit activeVisit = null; Encounter enounterAvailable = null; SimpleDateFormat mysqlDateTimeFormatter = new SimpleDateFormat("dd-MMM-yy"); Date dateEntered = null; try { dateEntered = mysqlDateTimeFormatter.parse(date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<Visit> activeVisitList = Context.getVisitService().getActiveVisitsByPatient(patient); for (Visit v : activeVisitList) { activeVisit = v; } List<Obs> obsAllList = Context.getObsService().getObservationsByPersonAndConcept(patient, Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); List<Obs> currentVisitObs = new ArrayList<Obs>(); for (Obs o : obsAllList) { if (o.getEncounter().getVisit().equals(activeVisit)) { currentVisitObs.add(o); } } for (Obs o : currentVisitObs) { enounterAvailable = o.getEncounter(); } if (enounterAvailable != null) { Date curDate = new Date(); SimpleDateFormat mysqlDateTimeFormatter1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); Date obsDateTime = null; String modifiedDate = new SimpleDateFormat("dd-MMM-yyyy") .format(enounterAvailable.getEncounterDatetime()); try { obsDateTime = mysqlDateTimeFormatter1.parse(modifiedDate + " " + curDate.getHours() + ":" + curDate.getMinutes() + ":" + curDate.getSeconds()); } catch (ParseException e) { obsDateTime = curDate; // TODO Auto-generated catch block e.printStackTrace(); } List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); for (Obs o : obsList) { if (o.getEncounter().equals(enounterAvailable)) { o.setVoided(true); o.setVoidReason("updated"); o.setDateVoided(new Date()); o.setVoidedBy(Context.getAuthenticatedUser()); } } Obs obs = new Obs(); obs.setEncounter(enounterAvailable); obs.setObsDatetime(obsDateTime); obs.setPerson(patient); obs.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation()); obs.setDateCreated(new Date()); obs.setCreator(Context.getAuthenticatedUser()); obs.setValueDatetime(dateEntered); obs.setConcept(Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); obs.setComment("next apointment"); Context.getObsService().saveObs(obs, null); } else { Date curDate = new Date(); SimpleDateFormat mysqlDateTimeFormatter1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); Date encounterDateTime = null; if (activeVisit != null) { String modifiedDate = new SimpleDateFormat("dd-MMM-yyyy").format(activeVisit.getStartDatetime()); try { encounterDateTime = mysqlDateTimeFormatter1.parse(modifiedDate + " " + curDate.getHours() + ":" + curDate.getMinutes() + ":" + curDate.getSeconds()); } catch (ParseException e) { encounterDateTime = curDate; // TODO Auto-generated catch block e.printStackTrace(); } } Encounter newEncounter = new Encounter(); newEncounter.setEncounterType( Context.getEncounterService().getEncounterTypeByUuid("465a92f2-baf8-42e9-9612-53064be868e8")); newEncounter.setPatient(patient); newEncounter.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation()); newEncounter.setDateCreated(new Date()); newEncounter.setEncounterDatetime(encounterDateTime); newEncounter.setVisit(activeVisit); newEncounter.setCreator(Context.getAuthenticatedUser()); newEncounter.setVoided(false); enounterAvailable = Context.getEncounterService().saveEncounter(newEncounter); List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); for (Obs o : obsList) { if (o.getEncounter().equals(enounterAvailable)) { o.setVoided(true); o.setVoidReason("updated"); o.setDateVoided(new Date()); o.setVoidedBy(Context.getAuthenticatedUser()); } } Obs obs = new Obs(); obs.setEncounter(enounterAvailable); obs.setObsDatetime(encounterDateTime); obs.setPerson(patient); obs.setDateCreated(new Date()); obs.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation()); obs.setCreator(Context.getAuthenticatedUser()); obs.setValueDatetime(dateEntered); obs.setConcept(Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); obs.setComment("next apointment"); Context.getObsService().saveObs(obs, null); } int totalPatient = 0; JSONObject drugsInfoDetailsJson = new JSONObject(); drugsInfoDetailsJson.put("count", totalPatient); return drugsInfoDetailsJson; }
From source file:eionet.util.Util.java
/** * A method for calculating and formatting the current date and time into a String for a log. *///from ww w . j av a 2 s .co m public static String logTime() { Date date = new Date(); String month = String.valueOf(date.getMonth()); month = (month.length() < 2) ? ("0" + month) : month; String day = String.valueOf(date.getDate()); day = (day.length() < 2) ? ("0" + day) : day; String hours = String.valueOf(date.getHours()); hours = (hours.length() < 2) ? ("0" + hours) : hours; String minutes = String.valueOf(date.getMinutes()); minutes = (minutes.length() < 2) ? ("0" + minutes) : minutes; String seconds = String.valueOf(date.getSeconds()); seconds = (seconds.length() < 2) ? ("0" + seconds) : seconds; String time = "[" + month; time = time + "/" + day; time = time + " " + hours; time = time + ":" + minutes; time = time + ":" + seconds; time = time + "] "; return time; }
From source file:net.cit.tetrad.dao.management.impl.SubDaoImpl.java
/** * ? ?/*from www . java 2s . co m*/ * @param dto * @return gdInfo * @throws Exception */ public GraphDefInfo getGraphDefInfoForSubGraph(CommonDto dto) { GraphDefInfo gdInfo = new GraphDefInfo(); try { String graphPeriod = StringUtils.getDefaultValueIfNull(dto.getGraph_period(), "1"); dto.setGraph_period(graphPeriod); String startDate = dto.getSdate(); int deviceCode = dto.getDeviceCode(); String dsname = dto.getDsname(); Query query = setIdx(deviceCode); Device ddto = (Device) monadService.getFind(query, Device.class); dto.setUid(ddto.getUid()); Date stDate = DateUtil.plusHour(-2); Date edDate = new Date(); long startTime = mainDao.getSubGraphSearchTime(graphPeriod, DateUtil.getCurrentDate(stDate, "yyyy-MM-dd"), stDate.getHours() + "", stDate.getMinutes() + ""); long endTime = mainDao.getSubGraphSearchTime(graphPeriod, DateUtil.getCurrentDate(edDate, "yyyy-MM-dd"), edDate.getHours() + "", edDate.getMinutes() + ""); if (!StringUtils.isNull(startDate)) { startTime = mainDao.getSubGraphSearchTime(graphPeriod, startDate, dto.getGraph_shour(), dto.getGraph_smin()); endTime = mainDao.getSubGraphSearchTime(graphPeriod, dto.getEdate(), dto.getGraph_ehour(), dto.getGraph_emin()); } else { String stFullDate = DateUtil.getCurrentDate(stDate, "yyyy-MM-dd HH:mm"); String edFullDate = DateUtil.getCurrentDate(edDate, "yyyy-MM-dd HH:mm"); String[] stSplitDate = stFullDate.split(" "); String[] edSplitDate = edFullDate.split(" "); dto.setSdate(stSplitDate[0]); dto.setEdate(edSplitDate[0]); String[] stSplitTime = stSplitDate[1].split(":"); String[] edSplitTime = edSplitDate[1].split(":"); dto.setGraph_shour(stSplitTime[0]); dto.setGraph_smin(stSplitTime[1]); dto.setGraph_ehour(edSplitTime[0]); dto.setGraph_emin(edSplitTime[1]); } String[] filters = mainDao.setFilters(dsname, graphPeriod, ""); String[] graphLegend = mainDao.setGraphLegend(dsname); gdInfo.setFileName(dsname); gdInfo.setDevice(ddto); gdInfo.setStartTime(startTime); gdInfo.setEndTime(endTime); gdInfo.setFilters(filters); gdInfo.setGraphLegend(graphLegend); gdInfo.setWidth(SUB_SMALL_GRAPH_WIDTH); gdInfo.setHeight(SUB_SMALL_GRAPH_HEIGHT); gdInfo.setAxisTimeUnitDiv(graphPeriod); } catch (Exception e) { log.error(e, e); } return gdInfo; }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
@SuppressWarnings("deprecation") private void assertEqualsTime(Date date, int hours, int minutes, int seconds) { assertEquals(hours, date.getHours()); assertEquals(minutes, date.getMinutes()); assertEquals(seconds, date.getSeconds()); }
From source file:com.edgenius.wiki.blogsync.WordpressProxy.java
/** * Return "date_create_gmt" time is gmt, but timezone is wrong - it is local timezone. * Here will correct timezone and return date in local timezone. * @param date/*from w ww . j av a 2 s . c o m*/ * @return */ private Date fixInputTimezone(Date date) { if (date == null) return new Date();//??? Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.set(Calendar.YEAR, date.getYear() + 1900); cal.set(Calendar.MONTH, date.getMonth()); cal.set(Calendar.DATE, date.getDate()); cal.set(Calendar.HOUR_OF_DAY, date.getHours()); cal.set(Calendar.MINUTE, date.getMinutes()); cal.set(Calendar.SECOND, date.getSeconds()); Calendar local = Calendar.getInstance(TimeZone.getDefault()); local.setTimeInMillis(cal.getTimeInMillis()); return local.getTime(); }
From source file:eionet.util.Util.java
/** * A method for formatting the given timestamp into a String for history. * * @param timestamp Milliseconds since 1 January 1970. * @return formatted time as string in the form 2015/04/18 12:43. *///from w w w .j a v a 2 s . c o m public static String historyDate(long timestamp) { Date date = new Date(timestamp); String year = String.valueOf(1900 + date.getYear()); String month = String.valueOf(date.getMonth() + 1); month = (month.length() < 2) ? ("0" + month) : month; String day = String.valueOf(date.getDate()); day = (day.length() < 2) ? ("0" + day) : day; String hours = String.valueOf(date.getHours()); hours = (hours.length() < 2) ? ("0" + hours) : hours; String minutes = String.valueOf(date.getMinutes()); minutes = (minutes.length() < 2) ? ("0" + minutes) : minutes; String seconds = String.valueOf(date.getSeconds()); seconds = (seconds.length() < 2) ? ("0" + seconds) : seconds; String time = year; time = time + "/" + month; time = time + "/" + day; time = time + " " + hours; time = time + ":" + minutes; return time; }