List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:nl.b3p.viewer.admin.stripes.ApplicationSettingsActionBean.java
public Resolution publish() { // Find current published application and make backup try {/*from w w w . j ava 2s . c om*/ Application oldPublished = (Application) Stripersist.getEntityManager() .createQuery("from Application where name = :name AND version IS null").setMaxResults(1) .setParameter("name", name).getSingleResult(); Date nowDate = new Date(System.currentTimeMillis()); SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(); sdf.applyPattern("HH-mm_dd-MM-yyyy"); String now = sdf.format(nowDate); String uniqueVersion = findUniqueVersion(name, "B_" + now); oldPublished.setVersion(uniqueVersion); Stripersist.getEntityManager().persist(oldPublished); Stripersist.getEntityManager().getTransaction().commit(); } catch (NoResultException nre) { } application.setVersion(null); Stripersist.getEntityManager().persist(application); Stripersist.getEntityManager().getTransaction().commit(); setApplication(null); return new RedirectResolution(ChooseApplicationActionBean.class); }
From source file:gtu.jpa.hibernate.Rcdf002eDBUI.java
private JButton getJButton1x() { if (porcessDoAllBtn == null) { porcessDoAllBtn = new JButton(); porcessDoAllBtn.setText("\u6392\u7a0b\u57f7\u884c"); porcessDoAllBtn.setPreferredSize(new java.awt.Dimension(80, 54)); porcessDoAllBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String dateTime = processDoAllText.getText(); Validate.notBlank(dateTime, ""); Validate.isTrue(StringUtils.isNumeric(dateTime), ""); Validate.isTrue(StringUtils.isNumeric(dateTime), ""); Validate.isTrue(dateTime.length() == 14, "14"); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyyMMddHHmmss"); Date newDate = sdf.parse(dateTime); Validate.isTrue(newDate.after(new Date()), "??"); setTitle(DateFormatUtils.format(newDate, "yyyy/MM/dd HH:mm:ss") + "?..."); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { oneClickDoAll(); }/* ww w . j a v a 2 s . c om*/ }, newDate); } catch (Exception ex) { JCommonUtil.handleException(ex); setTitle("......" + ex.getMessage()); } } }); } return porcessDoAllBtn; }
From source file:org.betaconceptframework.astroboa.portal.utility.CalendarUtils.java
/** * Get a string of a certain date pattern form (e.g. YYYY-MM-DD i.e. 2008-03-29) and converts it to * a calendar object. // w ww . j a v a2 s .c o m * @param dateString * @param dateFormatPattern * @return */ public Calendar convertDateStringToCalendar(String dateString, String dateFormatPattern, TimeZone zone, Locale locale) { SimpleDateFormat dateFormat = (SimpleDateFormat) DateFormat.getDateInstance(); dateFormat.setLenient(false); // be strict in the formatting // apply accepted pattern dateFormat.applyPattern(dateFormatPattern); // get a date object try { Date date = dateFormat.parse(dateString); if (date != null) { Calendar calendar = new GregorianCalendar(zone, locale); calendar.setTime(date); return calendar; } else { return null; } } catch (Exception e) { logger.warn("The date string:" + dateString + " has an invalid format. The valid form is:" + dateFormatPattern, e); return null; } }
From source file:org.openthinclient.util.dpkg.DPKGPackageManager.java
/** * return the actually formatted date type in YYYY_MM_DD_HH_MM_ss * * @return String the actually formatted date *//*from ww w . j av a 2 s. c o m*/ private String getFormattedDate() { final SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy'_'MM'_'dd'_'HH'_'mm'_'ss"); return sdf.format(new GregorianCalendar().getTime()); }
From source file:fr.paris.lutece.plugins.dila.modules.solr.utils.parsers.DilaSolrLocalParser.java
/** * Event received at the end of the parsing operation * * @throws SAXException any SAX exception */// www . ja v a 2s .c om public void endDocument() throws SAXException { // 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; 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; } 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:net.solarnetwork.util.JavaBeanXmlSerializer.java
/** * Create a {@link SimpleDateFormat} and cache on the {@link #SDF} * ThreadLocal to re-use for all dates within a single response. * /* w w w .j a va 2s . c o m*/ * @param model * the model, to look for a TimeZone to format the dates in */ private Map<String, Object> setupDateFormat(Map<String, ?> model) { TimeZone tz = TimeZone.getTimeZone("GMT"); Map<String, Object> result = null; if (model != null) { result = new LinkedHashMap<String, Object>(); for (Map.Entry<String, ?> me : model.entrySet()) { Object o = me.getValue(); if (useModelTimeZoneForDates && o instanceof TimeZone) { tz = (TimeZone) o; } else if (modelKey != null) { if (modelKey.equals(me.getKey())) { result.put(modelKey, o); } } else { result.put(me.getKey(), o); } } } SimpleDateFormat sdf = new SimpleDateFormat(); if (tz.getRawOffset() == 0) { sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } else { sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); } sdf.setTimeZone(tz); if (logger.isTraceEnabled()) { logger.trace("TZ offset " + tz.getRawOffset()); } SDF.set(sdf); return result; }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting the description corresponding to Calendar * day//from w w w . ja va2 s. co m * * @param arg * @return */ public static String getDayDesc(Date arg) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("dd"); return sdf.format(arg).toUpperCase(); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting short description of month * // w w w . jav a 2s .c o m * @param month * @return */ public static String getMonthShortDesc(Date month) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("MMM"); return sdf.format(month).toUpperCase(); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting month description * //from www . j a v a 2 s. co m * @param month * @return */ public static String getMonthDesc(Date month) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("MM"); return sdf.format(month).toUpperCase(); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting month long description * /*w w w. j a v a 2 s . c o m*/ * @param month * @return */ public static String getMonthLongDesc(Date month) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("MMMMM"); return sdf.format(month); }