List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:pkg3lesautoelastic.Task.java
/** * * @param chunk the array of string to be processed * @param points_interest the points where things are located * @param distance the distance to consider on/off * @return A MultiKeyMap containing the following structure * <Point,Calendar,ArrayList> where the Points are contained in the * points_interest, the calendar is a time truncated to the format yyyy-MM-dd * HH:mm and the ArrayList contains Integer values of all users that passed * near the respective point/*from w w w . j av a2 s. c om*/ */ public MultiKeyMap run(String[] chunk, ArrayList<Point> points_interest, double distance) throws InterruptedException, ParseException { // System.out.println("TAMANHO DO CHUNK: " + chunk.length); Point[] gps_points = new Point[chunk.length]; //<point, calendar, arraylist<int>> MultiKeyMap output = new MultiKeyMap(); //extract points from chunk for (int i = 0; i < chunk.length; i++) { String strtmp = chunk[i].substring(chunk[i].indexOf("POINT(") + 6, chunk[i].length() - 1); String[] coordinates_chunk = strtmp.split(" "); double lati_chunk = Double.parseDouble(coordinates_chunk[0]); double longi_chunk = Double.parseDouble(coordinates_chunk[1]); gps_points[i] = new Point(lati_chunk, longi_chunk); } int countproc = 0; for (Point p2 : points_interest) { for (int i = 0; i < gps_points.length; i++) { countproc++; if (gps_points[i].distance(p2) <= distance) { // Formato: 156;2014-02-01 00:00:00.739166+01;POINT(41.8836718276551 12.4877775603346) String split = chunk[i].substring(chunk[i].indexOf(";") + 1, chunk[i].indexOf(".") - 3); SimpleDateFormat sdf1 = new SimpleDateFormat(); sdf1.applyPattern("yyyy-MM-dd HH:mm"); Calendar cal = new GregorianCalendar(); cal.setTime(sdf1.parse(split)); if (output.containsKey(p2, cal)) { int newUser = Integer.parseInt(chunk[i].substring(0, chunk[i].indexOf(";"))); ArrayList<Integer> tmp_array = ((ArrayList<Integer>) output.get(p2, cal)); if (!tmp_array.contains(newUser)) { tmp_array.add(newUser); } } else { output.put(p2, cal, new ArrayList<Integer>()); int newUser = Integer.parseInt(chunk[i].substring(0, chunk[i].indexOf(";"))); ((ArrayList<Integer>) output.get(p2, cal)).add(newUser); } } } } System.out.println("Points Chunk: " + gps_points.length + " Points Interess: " + points_interest.size() + " Loops: " + countproc); return output; }
From source file:org.jamwiki.parser.jflex.WikiSignatureTag.java
/** * *///from ww w . ja v a2s . co m private String buildWikiSignature(JFlexLexer lexer, boolean includeUser, boolean includeDate) { String signature = ""; if (includeUser) { signature = this.retrieveUserSignature(lexer.getParserInput()); // parse signature as link in order to store link metadata WikiLinkTag wikiLinkTag = new WikiLinkTag(); wikiLinkTag.parse(lexer, signature); if (lexer.getMode() != JFlexParser.MODE_MINIMAL) { try { signature = JFlexParserUtil.parseFragment(lexer.getParserInput(), signature, lexer.getMode()); } catch (ParserException e) { logger.severe("Failure while building wiki signature", e); // FIXME - return empty or a failure indicator? return ""; } } } if (includeUser && includeDate) { signature += " "; } if (includeDate) { SimpleDateFormat format = new SimpleDateFormat(); format.applyPattern(Environment.getValue(Environment.PROP_PARSER_SIGNATURE_DATE_PATTERN)); signature += format.format(new java.util.Date()); } return signature; }
From source file:Main.java
public void makeUI() { String[] zones = { "Asia/Tokyo", "Asia/Hong_Kong", "Asia/Calcutta", "Europe/Paris", "Europe/London", "America/New_York", "America/Los_Angeles" }; JLabel[] labels = new JLabel[zones.length]; SimpleDateFormat[] formats = new SimpleDateFormat[zones.length]; JFrame frame = new JFrame(); Calendar cal = Calendar.getInstance(); Date date = cal.getTime();/* w ww. j av a2 s . c o m*/ SpinnerDateModel model = new SpinnerDateModel(); model.setValue(date); JSpinner spinner = new JSpinner(model); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Date date = (Date) ((JSpinner) e.getSource()).getValue(); for (int i = 0; i < labels.length; i++) { labels[i].setText(formats[i].format(date)); } } }); SimpleDateFormat format = ((JSpinner.DateEditor) spinner.getEditor()).getFormat(); format.setTimeZone(TimeZone.getTimeZone(zones[0])); format.applyPattern("yyyy-MM-dd HH:mm:ss"); JPanel panel = new JPanel(new GridLayout(zones.length, 2, 10, 10)); for (int i = 0; i < zones.length; i++) { formats[i] = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); formats[i].setTimeZone(TimeZone.getTimeZone(zones[i])); JLabel label = new JLabel(zones[i]); labels[i] = new JLabel(formats[i].format(date)); panel.add(label); panel.add(labels[i]); } frame.setLayout(new BorderLayout()); frame.add(spinner, BorderLayout.NORTH); frame.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:surrey.csv.profile.expression.DateExpressionEvaluator.java
@Override public String evaluate(JSONObject exp, Map<String, String> valueMap) throws JSONException { Date date = new Date(); if (exp.has("value")) { String value = valueMap.get(exp.getString("value")); SimpleDateFormat inDf = new SimpleDateFormat(exp.getString("in")); try {/* ww w .jav a2 s. c o m*/ date = inDf.parse(value); } catch (ParseException e) { throw new JSONException( "Failed to convert value: " + value + " into a date using pattern: " + exp.getString("in")); } } if (exp.has("op")) { JSONObject op = exp.getJSONObject("op"); String opName = JSONObject.getNames(op)[0]; op = op.getJSONObject(opName); String field = JSONObject.getNames(op)[0]; int amount = op.getInt(field); int calField = Calendar.DAY_OF_MONTH; if (field.endsWith("s")) { field = field.substring(0, field.length() - 1); } if (field.equals("month")) { calField = Calendar.MONTH; } else if (field.equals("year")) { calField = Calendar.YEAR; } Calendar cal = Calendar.getInstance(); cal.setTime(date); if (opName.equals("add")) { cal.add(calField, amount); } else { cal.add(calField, -amount); } date = cal.getTime(); } SimpleDateFormat df = new SimpleDateFormat(); if (exp.has("out")) { df.applyPattern(exp.getString("out")); } return df.toPattern() + PATTERN_SEPARATOR + df.format(date); }
From source file:org.openehealth.coms.cc.web_frontend.consentcreator.controller.ConsentHistoryServiceServlet.java
/** * This method handles requests which aim to obtain the entire consent * history of a patient./* ww w .ja v a 2 s . c om*/ * */ private void requestTypeConsentHistory() { try { if (request.getParameter("emailaddress").trim().equalsIgnoreCase("")) { this.writeErrorMessage("Der bergebene Parameter Emailaddresse fehlt."); return; } User soughtUser = ccService.getUser((String) request.getParameter("emailaddress")); if (soughtUser == null) { writeErrorMessage("Die Liste der Dokumente des Patienten konnte nicht gefunden werden."); return; } Document domList = ccService.getConsentHistory(soughtUser.getID()); if (domList != null) { NodeList nl = domList.getElementsByTagName("ConsentDocument"); Vector<JSONObject> vjo = new Vector<JSONObject>(); for (int i = 0; i < nl.getLength(); i++) { JSONObject jso = new JSONObject(); jso.put("root", nl.item(i).getChildNodes().item(1).getAttributes().item(1).getNodeValue()); jso.put("extension", nl.item(i).getChildNodes().item(1).getAttributes().item(0).getNodeValue()); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyyMMddHHmmssZ"); Date d = sdf.parse(nl.item(i).getChildNodes().item(3).getAttributes().item(0).getNodeValue()); SimpleDateFormat displaysdf = new SimpleDateFormat(); displaysdf.applyPattern("dd.MM.yyyy HH:mm"); jso.put("effectiveTime", displaysdf.format(d)); vjo.add(jso); } JSONArray ja = new JSONArray(vjo); request.setAttribute("showList", "true"); request.setAttribute("show", "consenthistorypage"); request.setAttribute("list", ja); request.setAttribute("soughtUser", soughtUser); this.dispatch("/index.jsp"); } else { this.writeErrorMessage("Die Liste der Dokumente des Patienten konnte nicht gefunden werden."); } } catch (Exception e) { Logger.getLogger(this.getClass()).error(e); } }
From source file:ispok.converter.BirthDateConverter.java
@Override public String getAsString(FacesContext fc, UIComponent uic, Object o) { Locale locale = fc.getViewRoot().getLocale(); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); SimpleDateFormat sdf = (SimpleDateFormat) df; String pattern = sdf.toPattern(); pattern = pattern.replace("yy", "yyyy"); Date date = (Date) o;//from w w w . ja v a 2 s . co m sdf.applyPattern(pattern); return sdf.format(date); }
From source file:de.hybris.platform.servicelayer.cronjob.impl.DefaultJobLogConverterTest.java
@Test public void testValidFormatLogs() { final String pattern = "dd HH"; converter.setDateFormatPattern(pattern); final Date date = new Date(); final JobLogModel logEntry = new JobLogModel(); logEntry.setCreationtime(date);//from w w w . j a va2 s . com logEntry.setLevel(JobLogLevel.FATAL); final List<JobLogModel> entries = Arrays.asList(logEntry); final String result = converter.convert(entries); Mockito.verify(formatFactory, Mockito.times(1)).createDateTimeFormat(DateFormat.DEFAULT, -1); final SimpleDateFormat sdf = (SimpleDateFormat) formatFactory.createDateTimeFormat(DateFormat.DEFAULT, -1); sdf.applyPattern(pattern); Assert.assertEquals(result, String.format("%s: FATAL: <empty>" + CharUtils.LF, sdf.format(date))); }
From source file:net.sf.jasperreports.engine.util.JRDateLocaleConverter.java
@Override protected Object parse(Object value, String pattern) throws ParseException { SimpleDateFormat formatter = getFormatter(pattern, locale); if (pattern != null) { if (locPattern) { formatter.applyLocalizedPattern(pattern); } else {/*from w ww .j a va 2 s. com*/ formatter.applyPattern(pattern); } } return formatter.parse((String) value); }
From source file:com.funambol.exchange.util.DateTools.java
/** * <p>/* ww w . ja v a 2s .c o m*/ * Convert a date in WebDav format ("yyyy-MM-dd'T'KK:mm:ss.fff'Z'") in day * format ("yyyy-MM-dd") * </p> * * @param date * @param timezone * @param isAStartDate * flag that tells if the input String represents a start date * @return the date in day format * @throws XmlParseException */ public static String convertWebDavDateToDay(String date, String timezone) throws XmlParseException { SimpleDateFormat formatter; Date dt; String funambolDate; if (date != null && date.length() > 0) { formatter = new SimpleDateFormat(DATE_FORMAT_WEBDAV); try { formatter.setTimeZone(TimeZone.getTimeZone("GMT")); dt = formatter.parse(date); long time = dt.getTime(); long offset = TimeZone.getTimeZone(timezone).getOffset(time); dt = new Date(time + offset); } catch (ParseException e) { throw new XmlParseException("Error converting date", e); } formatter.applyPattern(DateTools.ANNIVERSARY_FORMAT_PDI); funambolDate = formatter.format(dt); } else { funambolDate = null; } return funambolDate; }
From source file:de.hybris.platform.servicelayer.cronjob.impl.DefaultJobLogConverterTest.java
@Test public void testValidFormatLogsWithEntries() { final String pattern = "dd HH"; converter.setDateFormatPattern(pattern); final StringBuilder messageBuilder = new StringBuilder(1000); for (int i = 0; i < 5; i++) { messageBuilder.append("message" + i + CharUtils.LF); }/* w w w .j ava 2s . c om*/ final Date date = new Date(); final JobLogModel logEntry = new JobLogModel(); logEntry.setCreationtime(date); logEntry.setLevel(JobLogLevel.FATAL); logEntry.setMessage(messageBuilder.toString()); final List<JobLogModel> entries = Arrays.asList(logEntry); final String result = converter.convert(entries); Mockito.verify(formatFactory, Mockito.times(1)).createDateTimeFormat(DateFormat.DEFAULT, -1); final SimpleDateFormat sdf = (SimpleDateFormat) formatFactory.createDateTimeFormat(DateFormat.DEFAULT, -1); sdf.applyPattern(pattern); Assert.assertEquals(result, String.format("%s: FATAL: " + messageBuilder.toString(), sdf.format(date))); }