List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for converting date to string with specific pattern * /*ww w.java 2 s . c o m*/ * @param dateArg * @param pattern * @return */ public static String convertDateToString(Date dateArg, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(pattern); return sdf.format(dateArg); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for converting format dd-MM-yyyy to date * //from w w w . j a v a 2s .c o m * @param strDate * @return * @throws ParseException */ public static Timestamp convertStringToTimestamp(String strDate) throws ParseException { Calendar c = GregorianCalendar.getInstance(); c.setTimeInMillis(Long.valueOf(strDate)); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(DateTimeConstants.TIMESTAMP_FORMAT); String ts = sdf.format(c.getTime()); return Timestamp.valueOf(ts); }
From source file:fr.paris.lutece.plugins.dila.modules.solr.utils.parsers.DilaSolrPublicParser.java
/** * Event received at the end of the parsing operation * * @throws SAXException any SAX exception *///from ww w.j av a2s . c om public void endDocument() throws SAXException { // Sets the ID // Sets the full URL UrlItem url = new UrlItem(_strProdUrl); url.addParameter(XPageAppService.PARAM_XPAGE_APP, AppPropertiesService.getProperty(PROPERTY_PLUGIN_NAME)); url.addParameter(AppPropertiesService.getProperty(PROPERTY_PATH_ID), _strId); url.addParameter(AppPropertiesService.getProperty(PROPERTY_PATH_CATEGORY), _strAudience); // Converts the date from "dd MMMMM yyyy" to "yyyyMMdd" Locale locale = Locale.FRENCH; Date dateUpdate = null; if (StringUtils.isNotEmpty(_strDate)) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", locale); String strDate = _strDate.split(STRING_SPACE)[1]; dateUpdate = dateFormat.parse(strDate); dateFormat.applyPattern("yyyyMMdd"); } catch (ParseException e) { dateUpdate = null; } } else { dateUpdate = null; } if (StringUtils.isNotEmpty(_strId)) { // Creates a new lucene document SolrItem item = new SolrItem(); item.setUrl(url.getUrl()); item.setDate(dateUpdate); item.setUid(_strId); item.setContent(_strContents); item.setTitle(_strTitle); item.setType(_strType); item.setSite(_strSite); String[] categories = new String[] { _strAudience }; item.setCategorie(Arrays.asList(categories)); // Adds the new item to the list _listSolrItems.add(item); } }
From source file:org.openmrs.web.dwr.DWRPersonService.java
/** * Private method to handle birth date and age input. * * @param birthdate//w w w.j a va 2s. c om * @param dateformat * @param age * @return * @throws java.text.ParseException */ private Date updateAge(String birthdate, String dateformat, String age) throws java.text.ParseException { SimpleDateFormat df = new SimpleDateFormat(); if (!"".equals(dateformat)) { dateformat = dateformat.toLowerCase().replaceAll("m", "M"); } else { dateformat = new String("MM/dd/yyyy"); } df.applyPattern(dateformat); Calendar cal = Calendar.getInstance(); cal.clear(Calendar.HOUR); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); if ("".equals(birthdate)) { if ("".equals(age)) { return cal.getTime(); } try { cal.add(Calendar.YEAR, -(Integer.parseInt(age))); } catch (NumberFormatException nfe) { log.error("Error during adding date into calendar", nfe); } return cal.getTime(); } else { cal.setTime(df.parse(birthdate)); } return cal.getTime(); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java
private String getDayFromDate(String timeOfMeasurement, String dateFormat, String applyPattern) { SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); try {/*from www . j a v a2 s .co m*/ Date today = sdf.parse(timeOfMeasurement); sdf.applyPattern(applyPattern); return sdf.format(today); } catch (ParseException e) { e.printStackTrace(); Log.e(TAG, e.toString()); } return ""; }
From source file:com.appeligo.search.actions.account.BaseAccountAction.java
protected String setBirthMonthYear(User user) { SimpleDateFormat format = new SimpleDateFormat(); if (getBirthYear() != null && getBirthYear().length() == 4) { if (getBirthMonth() != null && getBirthMonth().length() == 3) { format.applyPattern("yyyy MMM"); try { java.util.Date date = format.parse(getBirthYear() + " " + getBirthMonth()); java.sql.Date birthMonthYear = new java.sql.Date(date.getTime()); user.setBirthMonthYear(birthMonthYear); } catch (ParseException e) { addActionError(getText("username.bothmonthyear")); }/* w w w.ja v a2s .c o m*/ } else { addActionError(getText("username.bothmonthyear")); return INPUT; } } else if (getBirthMonth() != null && getBirthMonth().length() == 3) { addActionError(getText("username.bothmonthyear")); return INPUT; } return SUCCESS; }
From source file:com.jackie.refresh.RefreshLayoutBase.java
/** * Header View//from w w w . j a va 2s .c o m */ private void updateHeaderTimeStamp() { // mTimeTxt.setText(R.string.txt_last_update_time); SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getInstance(); sdf.applyPattern("yyyy-MM-dd HH:mm:ss"); mTimeTxt.append(sdf.format(new Date())); }
From source file:eionet.gdem.utils.MultipartFileUpload.java
/** * Appends current date value at the end of the filename. * * @param folderName/*w ww . ja v a2s .c o m*/ * Folder where the file will be stored * @param fileName * File name that should be used for generating the unique filename * * @return Filename with appended date (in format yyMMddHHmmss) */ private File getDateAappendedFile(String folderName, String fileName) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyMMddHHmmss"); String dateVal = sdf.format(new Date()); int pos = fileName.lastIndexOf("."); StringBuffer buf = new StringBuffer(); buf.append(fileName.substring(0, pos)); buf.append("_"); buf.append(dateVal); buf.append(fileName.substring(pos)); return getUniqueFile(folderName, buf.toString()); }
From source file:paquete.Ventana.java
private void jButtonBanderaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBanderaActionPerformed //Incremento el Numero de Ticket contadorTicket++;// w w w. j a va 2s .c o m DecimalFormat formato = new DecimalFormat("00000"); jTextAreaTicket.setText(""); jTextAreaTicket.append("TICKET\n======\n"); jTextAreaTicket.append("N ticket: " + formato.format(contadorTicket) + "\n"); // Obtenenmos la Fecha Actual formato.applyPattern("00"); Calendar rightNow = Calendar.getInstance(); iniMilisegundos = rightNow.getTimeInMillis(); //Mostramos la Fecha en formato DD-MM-YYYY SimpleDateFormat horaActual = new SimpleDateFormat("d-M-y"); jTextAreaTicket.append("Fecha: " + horaActual.format(rightNow.getTime()) + "\n\n"); //Mostramos la Hora en formato HH:MI:SS horaActual.applyPattern("HH:mm:ss"); jTextAreaTicket.append("Hora bajada de bandera: " + horaActual.format(rightNow.getTime()) + "\n"); //Ponemos las coordenadas muestraCoordenadas(); // Cambiamos de orden la habilitacion de botones jButtonBandera.setEnabled(false); jButtonFin.setEnabled(true); }
From source file:org.apache.roller.weblogger.webservices.atomprotocol.MediaCollection.java
/** * Creates a file name for a file based on a weblog, title string and a * content-type. /*from w ww . j av a2 s .c om*/ * * @param weblog Weblog for which file name is being created * @param title Title to be used as basis for file name (or null) * @param contentType Content type of file (must not be null) * * If a title is specified, the method will apply the same create-anchor * logic we use for weblog entries to create a file name based on the title. * * If title is null, the base file name will be the weblog handle plus a * YYYYMMDDHHSS timestamp. * * The extension will be formed by using the part of content type that * comes after he slash. * * For example: * weblog.handle = "daveblog" * title = "Port Antonio" * content-type = "image/jpg" * Would result in port_antonio.jpg * * Another example: * weblog.handle = "daveblog" * title = null * content-type = "image/jpg" * Might result in daveblog-200608201034.jpg */ private String createFileName(Weblog weblog, String slug, String contentType) { if (weblog == null) throw new IllegalArgumentException("weblog cannot be null"); if (contentType == null) throw new IllegalArgumentException("contentType cannot be null"); String fileName = null; // Determine the extension based on the contentType. This is a hack. // The info we need to map from contentType to file extension is in // JRE/lib/content-type.properties, but Java Activation doesn't provide // a way to do a reverse mapping or to get at the data. String[] typeTokens = contentType.split("/"); String ext = typeTokens[1]; if (slug != null && !slug.trim().equals("")) { // We've got a title, so use it to build file name StringTokenizer toker = new StringTokenizer(slug); String tmp = null; int count = 0; while (toker.hasMoreTokens() && count < 5) { String s = toker.nextToken(); s = s.toLowerCase(); tmp = (tmp == null) ? s : tmp + "_" + s; count++; } if (!tmp.endsWith("." + ext)) { fileName = tmp + "." + ext; } else { fileName = tmp; } } else { // No title or text, so instead we'll use the item's date // in YYYYMMDD format to form the file name SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyyMMddHHSS"); fileName = weblog.getHandle() + "-" + sdf.format(new Date()) + "." + ext; } return fileName; }