public Object objectDone() { Object o = super.objectDone(); BSONObject b = (BSONObject) o; if (!_lastArray) { if (b.containsField("$oid")) { o = new ObjectId((String) b.get("$oid")); if (!isStackEmpty()) { gotObjectId(_lastName, (ObjectId) o); } else { setRoot(o); } } else if (b.containsField("$date")) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT"))); o = format.parse((String) b.get("$date"), new ParsePosition(0)); if (!isStackEmpty()) { cur().put(_lastName, o); } else { setRoot(o); } } else if (b.containsField("$regex")) { o = Pattern.compile((String) b.get("$regex"), BSON.regexFlags((String) b.get("$options"))); if (!isStackEmpty()) { cur().put(_lastName, o); } else { setRoot(o); } } } return o; }
public static void main(String[] args) { Scanner in = new Scanner(System.in); String time = in.next(); // Set format for input and output SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ssa"); SimpleDateFormat out = new SimpleDateFormat("HH:mm:ss"); try { Date inTime = sdf.parse(time); System.out.println(out.format(inTime)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public String _tstamp(String args[]) { String format = "yyyyMMddHHmm"; long now = System.currentTimeMillis(); TimeZone tz = TimeZone.getTimeZone("UTC"); if (args.length > 1) { format = args[1]; } if (args.length > 2) { tz = TimeZone.getTimeZone(args[2]); } if (args.length > 3) { now = Long.parseLong(args[3]); } if (args.length > 4) { domain.warning("Too many arguments for tstamp: " + Arrays.toString(args)); } SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setTimeZone(tz); return sdf.format(new Date(now)); }
public String getId(Connection con) throws Exception { String ret = null; String sql = "select seq_id.nextval from dual"; Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql); if (rs.next()) { ret = sdf2.format(new java.util.Date()) + rs.getString(1); } else { throw new Exception("fail get id from oracle seq_id"); } rs.close(); st.close(); return ret; }
public List getIterationList(String projectId) { List<Map> list = new ArrayList<Map>(); try { String apiUrl = rallyApiHost + "/iteration?" + "project=" + rallyApiHost + "/project/" + projectId + "&fetch=true&order=Name%20desc&start=1&pagesize=100"; String checkProjectRef = rallyApiHost + "/project/" + projectId; log.info("rallyApiUrl:" + apiUrl); log.info("checkProjectRef:" + checkProjectRef); String responseXML = getRallyXML(apiUrl); SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Date currentDate = new Date(); org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder(); org.jdom.Document doc = bSAX.build(new StringReader(responseXML)); Element root = doc.getRootElement(); XPath xpath = XPath.newInstance("//Object"); List xlist = xpath.selectNodes(root); Iterator iter = xlist.iterator(); while (iter.hasNext()) { Map map = new HashMap(); Element item = (Element) iter.next(); String objId = item.getChildText("ObjectID"); String name = item.getChildText("Name"); String state = item.getChildText("State"); String startDateStr = item.getChildText("StartDate"); String endDateStr = item.getChildText("EndDate"); Date startDate = ISO8601FORMAT.parse(startDateStr); Date endDate = ISO8601FORMAT.parse(endDateStr); boolean isCurrent = false; int startCheck = startDate.compareTo(currentDate); int endCheck = endDate.compareTo(currentDate); if (startCheck < 0 && endCheck > 0) { isCurrent = true; } log.info("name=" + name + " isCurrent=" + isCurrent); String releaseRef = item.getAttribute("ref").getValue(); // In child project, parent object have to be filiered Element projectElement = item.getChild("Project"); String projectRef = projectElement.getAttributeValue("ref"); if (projectRef.equals(checkProjectRef)) { map.put("objId", objId); map.put("rallyRef", releaseRef); map.put("name", name); map.put("state", state); map.put("isCurrent", "" + isCurrent); list.add(map); } } log.info("-----------"); } catch (Exception ex) { log.error("ERROR: ", ex); } return list; }
private String formatDate(Date myDate) { String strFormat = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat formatter = new SimpleDateFormat(strFormat); String strDate = formatter.format(myDate); return strDate; }