List of usage examples for java.text DateFormat MEDIUM
int MEDIUM
To view the source code for java.text DateFormat MEDIUM.
Click Source Link
From source file:taximetro.main.java
private void jButtoncomienzoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtoncomienzoActionPerformed //Establecer parmetros del nuevo estado de los botones comiezo y fin // de carrera, despus de la accin del botn. jButtonfin.setEnabled(true);//from w ww. j a v a2s . c o m jButtoncomienzo.setEnabled(false); //Borrado del texto existente del area de texto. jTextAreaticket.setText(""); //Guardar la hora de comienzo de carrera al presionar el boton de comenzar. Calendar tiempo = Calendar.getInstance(zona); DateFormat formatohoras = DateFormat.getTimeInstance(DateFormat.MEDIUM); horacomienzocarrera = formatohoras.format(tiempo.getTimeInMillis()); //Establecer contador de tiempo ponerlo a cero, y inicarlo. cronometro.reset(); cronometro.start(); //Establecer contador del nmero de ticket. ticket++; //Darle formato al nmero del ticket con 5 dgitos, sin punto. NumberFormat formato = NumberFormat.getInstance(); formato.setMinimumIntegerDigits(5); formato.setGroupingUsed(false); textoticket = String.valueOf(formato.format(ticket)); }
From source file:com.idega.block.cal.renderer.ScheduleDetailedDayRenderer.java
protected void writeEntries(FacesContext context, HtmlSchedule schedule, ScheduleDay day, ResponseWriter writer, int index) throws IOException { //final String clientId = schedule.getClientId(context); //FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context); //String formId = parentFormInfo == null ? null : parentFormInfo.getFormName(); TreeSet entrySet = new TreeSet(); for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();) { entrySet.add(new EntryWrapper((ScheduleEntry) entryIterator.next(), day)); }//from w w w. ja va 2 s . com EntryWrapper[] entries = (EntryWrapper[]) entrySet.toArray(new EntryWrapper[entrySet.size()]); //determine overlaps scanEntries(entries, 0); //determine the number of columns within this day int maxColumn = 0; for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) { EntryWrapper wrapper = (EntryWrapper) entryIterator.next(); maxColumn = Math.max(wrapper.column, maxColumn); } int numberOfColumns = maxColumn + 1; //make sure the entries take up all available space horizontally maximizeEntries(entries, numberOfColumns); //now determine the width in percent of 1 column float columnWidth = 100 / numberOfColumns; //and now draw the entries in the columns for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) { EntryWrapper wrapper = (EntryWrapper) entryIterator.next(); boolean selected = isSelected(schedule, wrapper); //compose the CSS style for the entry box StringBuffer entryStyle = new StringBuffer(); entryStyle.append(wrapper.getBounds(schedule, columnWidth, index)); if (selected) { writer.startElement(HTML.DIV_ELEM, schedule); writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entry-selected"), null); //draw the tooltip if (showTooltip(schedule)) { getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected); } //draw the content getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false, selected); writer.endElement(HTML.DIV_ELEM); } else { //if the schedule is read-only, the entries should not be //hyperlinks writer.startElement(schedule.isReadonly() ? HTML.DIV_ELEM : HTML.ANCHOR_ELEM, schedule); //draw the tooltip if (showTooltip(schedule)) { getEntryRenderer(schedule).renderToolTip(context, writer, schedule, wrapper.entry, selected); } if (!schedule.isReadonly()) { DateFormat format; String pattern = null; if ((pattern != null) && (pattern.length() > 0)) { format = new SimpleDateFormat(pattern); } else { if (context.getApplication().getDefaultLocale() != null) { format = DateFormat.getDateInstance(DateFormat.MEDIUM, context.getApplication().getDefaultLocale()); } else { format = DateFormat.getDateInstance(DateFormat.MEDIUM); } } String startTime = format.format(wrapper.entry.getStartTime()); startTime += " "; startTime += wrapper.entry.getStartTime().getHours(); startTime += ":"; if (wrapper.entry.getStartTime().getMinutes() < 10) { startTime += "0"; startTime += wrapper.entry.getStartTime().getMinutes(); } else { startTime += wrapper.entry.getStartTime().getMinutes(); } String endTime = ""; endTime += wrapper.entry.getEndTime().getHours(); endTime += ":"; if (wrapper.entry.getEndTime().getMinutes() < 10) { endTime += "0"; endTime += wrapper.entry.getEndTime().getMinutes(); } else { endTime += wrapper.entry.getEndTime().getMinutes(); } writer.writeAttribute(HTML.HREF_ATTR, "javascript:void(0)", null); writer.writeAttribute("entryid", wrapper.entry.getId(), null); } if (schedule.getModel().size() == 1) { writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entry"), null); } else { writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "workweekEntry"), null); } writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null); //draw the content getEntryRenderer(schedule).renderContent(context, writer, schedule, day, wrapper.entry, false, selected); writer.endElement(schedule.isReadonly() ? HTML.DIV_ELEM : "a"); } } }
From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java
/** * This methods tries to convert a generic object into a java.util.Date instance. * Supported types are for now String, Long values (time millis) and Date subtypes * like for example java.sql.Date./* w ww . j a v a 2 s. com*/ */ private Date convertDateObject(Object dateObject) { if (dateObject == null) { if (log.isDebugEnabled()) { log.debug("The date object can not be null."); } return null; } else if (dateObject instanceof String) { // Try to convert using the different style for pattern. // We use MEDIUM as the first one because it is the DEFAULT int formatTypes[] = new int[] { DateFormat.MEDIUM, DateFormat.SHORT, DateFormat.LONG, DateFormat.FULL }; for (int formatType : formatTypes) { try { DateFormat df = DateFormat.getDateInstance(formatType, getReportLocale()); df.setTimeZone(getReportTimeZone()); return df.parse((String) dateObject); } catch (ParseException e) { if (log.isDebugEnabled()) { log.debug("Unable to parse the string as Date using the standard SimpleDateFormat."); } } } return null; } else if (dateObject instanceof Long) { Calendar cal = Calendar.getInstance(getReportTimeZone(), getReportLocale()); cal.setTimeInMillis((Long) dateObject); return cal.getTime(); } else if (dateObject instanceof Date) { return (Date) dateObject; } if (log.isDebugEnabled()) { log.debug("The specified object is not among the allowed types for Date conversion."); } return null; }
From source file:org.pentaho.platform.scheduler.SchedulerAdminUIComponent.java
/** * This formatter works with a date/time string with this format: * May 21, 2008 8:29:21 PM/* www. j ava2s . co m*/ * * NOTE: the formatter cannot be shared across threads (since DateFormat implementations * are not guaranteed to be thread safe) or across sessions (since different * sessions may have different locales). So create a new one an each call. * @return */ private DateFormat getDateTimeFormatter() { return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, LocaleHelper.getLocale()); }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
private void generateCertificateKeyUsageNotForEncryption() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c" + "0201000281810096383c89ad7b3c3be9dfcb24c1ba2b19f681847eaf862c" + "eec3cb2daf20da3f68f30221b46444c259228cc84f35095af19d2496a486" + "b4e818ce17241dd792a6c6ad07f8601c728f71f8016e1dbc5905fade3ecf" + "37b6374f4668bb3a5de16059125cea11ef3bd712a375dd33894670faa18b" + "8c733227a530ec569fcb5ade02523d020301000102818030202c24df934f" + "a4d234845c6e443a72c2ea938c12a7a5d5889c9b32341037a863d2170237" + "ed5f66370f6b4d14ecbe5a11c21b10f2a71a8477e22a0bf578623d5e961d" + "41151118d6114296baa55c479a33de26ef872f61eb59388bddb43c970614" + "52983edf79e71def89879820f06667b237be04b1fb18eaa203fb59d82ebc" + "71024100c9b7820310a62a3815564519a038bcfd99965ed9adf494214fca" + "d0d08019b9ba6821bcfc9faf448f1650e9e7aeba6b9ce3e7d6f9449c1897" + "d7dd7d0f4e8c39fb024100bea50896dc44c9cd710611e229fd7fe01c06f8" + "db7ea4428c99b243ba26937eaedfd9fae5eed02e292a8a4c7092320e29dc" + "143223b85cfeb43efbb1603ebce72702407bc7f82819575e20fc36ec4045" + "698bcfb327eb1c78fad4cb7c4360d0114bb805035170bf34de409bed7dc9" + "8b3a557b23d356b93c4d35dc81911d81589b42c17102406eb7cfc6358469" + "a2bb8a27e6ae364006baa03df4d396b7e389fb62a4007556745f22ec388f" + "3a2e24d044e361d935e2cde2b783eb04ce5549feee13b46e9b2caf024100" + "a8c35546c2241ce9b90b14c667d2b83512a6ad3b50f1511696c3eb7f608b" + "c292bad19c4fe11b466a045ebfdb92f371199369e22e5ce6a16578c9a25c" + "7b67e997"; String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d003081890281810096" + "383c89ad7b3c3be9dfcb24c1ba2b19f681847eaf862ceec3cb2daf20da3f" + "68f30221b46444c259228cc84f35095af19d2496a486b4e818ce17241dd7" + "92a6c6ad07f8601c728f71f8016e1dbc5905fade3ecf37b6374f4668bb3a" + "5de16059125cea11ef3bd712a375dd33894670faa18b8c733227a530ec56" + "9fcb5ade02523d0203010001"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email = "test@example.com"; subjectBuilder.setCommonName("Valid certificate"); subjectBuilder.setEmail(email);/*from www .j a v a 2 s .com*/ subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); // use TreeSet because we want a deterministic certificate (ie. hash should not change) Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("1178c336c7b51cadd4ccecdd14daf22", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 10:38:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, true /* critical */); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); certificateBuilder.addSubjectKeyIdentifier(true); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("KeyUsageNotForEncryption", privateKey, null, chain); }
From source file:org.muse.mneme.impl.ImportServiceImpl.java
/** * Add a formatted date to a source string, using a message selector. * // w w w . j a v a2 s. c om * @param selector * The message selector. * @param source * The original string. * @param date * The date to format. * @return The source and date passed throught the selector message. */ protected String addDate(String selector, String source, Date date) { // format the date DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String fmt = format.format(date); // the args Object[] args = new Object[2]; args[0] = source; args[1] = fmt; // format the works String rv = this.messages.getFormattedMessage(selector, args); return rv; }
From source file:org.openehealth.pors.core.PorsCoreBean.java
/** * @see IPorsCore#assembleDuplicateEntryDTO(DuplicateEntry) *//*from w w w .j a v a 2 s. com*/ public DuplicateEntryDTO assembleDuplicateEntryDTO(DuplicateEntry duplicate) { DuplicateEntryDTO duplicateDTO = new DuplicateEntryDTO(); duplicateDTO.setDomain(duplicate.getId().getDomain()); duplicateDTO.setLogTime(duplicate.getTimestamp()); duplicateDTO .setLogDateString(DateFormat.getDateInstance(DateFormat.MEDIUM).format(duplicate.getTimestamp())); DateFormat dfmt = new SimpleDateFormat("HH:mm:ss:SS"); duplicateDTO.setLogTimeString(dfmt.format(duplicate.getTimestamp())); NumberFormat formatter = new DecimalFormat("#0.00"); duplicateDTO.setPercentage(formatter.format(duplicate.getValue() * 100.0)); duplicateDTO.setId1(duplicate.getId().getId1()); duplicateDTO.setId2(duplicate.getId().getId2()); return duplicateDTO; }
From source file:org.hoteia.qalingo.core.web.mvc.factory.impl.BackofficeViewBeanFactoryImpl.java
/** * @throws Exception// ww w .java 2 s . c o m * */ public CatalogCategoryViewBean buildMasterCatalogCategoryViewBean(final RequestData requestData, final CatalogCategoryMaster catalogCategory, boolean fullPopulate) throws Exception { final MarketArea currentMarketArea = requestData.getMarketArea(); final CatalogCategoryViewBean catalogCategoryViewBean = new CatalogCategoryViewBean(); if (catalogCategory != null) { final String categoryCode = catalogCategory.getCode(); catalogCategoryViewBean.setName(catalogCategory.getBusinessName()); catalogCategoryViewBean.setCode(categoryCode); catalogCategoryViewBean.setDescription(catalogCategory.getDescription()); if (catalogCategory.getDefaultParentCatalogCategory() != null) { // TODO : Denis : fetch optim - cache : we reload entity to fetch the defaultParentCatalogCategory CatalogCategoryMaster defaultParentCatalogCategory = catalogCategoryService .getMasterCatalogCategoryById(catalogCategory.getDefaultParentCatalogCategory().getId()); catalogCategoryViewBean.setDefaultParentCategory( buildMasterCatalogCategoryViewBean(requestData, defaultParentCatalogCategory, false)); } DateFormat dateFormat = requestUtil.getFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM); Date createdDate = catalogCategory.getDateCreate(); if (createdDate != null) { catalogCategoryViewBean.setCreatedDate(dateFormat.format(createdDate)); } else { catalogCategoryViewBean.setCreatedDate(Constants.NOT_AVAILABLE); } Date updatedDate = catalogCategory.getDateUpdate(); if (updatedDate != null) { catalogCategoryViewBean.setUpdatedDate(dateFormat.format(updatedDate)); } else { catalogCategoryViewBean.setUpdatedDate(Constants.NOT_AVAILABLE); } if (fullPopulate) { if (catalogCategory.getCatalogCategories() != null) { catalogCategoryViewBean.setSubCategories(buildMasterCatalogCategoryViewBeans(requestData, new ArrayList<CatalogCategoryMaster>(catalogCategory.getCatalogCategories()), fullPopulate)); } List<CatalogCategoryMasterAttribute> globalAttributes = catalogCategory .getCatalogCategoryGlobalAttributes(); for (Iterator<CatalogCategoryMasterAttribute> iterator = globalAttributes.iterator(); iterator .hasNext();) { CatalogCategoryMasterAttribute catalogCategoryMasterAttribute = (CatalogCategoryMasterAttribute) iterator .next(); catalogCategoryViewBean.getGlobalAttributes().put( catalogCategoryMasterAttribute.getAttributeDefinition().getCode(), catalogCategoryMasterAttribute.getValueAsString()); } List<CatalogCategoryMasterAttribute> marketAreaAttributes = catalogCategory .getCatalogCategoryMarketAreaAttributes(currentMarketArea.getId()); for (Iterator<CatalogCategoryMasterAttribute> iterator = marketAreaAttributes.iterator(); iterator .hasNext();) { CatalogCategoryMasterAttribute catalogCategoryMasterAttribute = (CatalogCategoryMasterAttribute) iterator .next(); catalogCategoryViewBean.getMarketAreaAttributes().put( catalogCategoryMasterAttribute.getAttributeDefinition().getCode(), catalogCategoryMasterAttribute.getValueAsString()); } List<ProductMarketingViewBean> productMarketingViewBeans = buildProductMarketingViewBeans( requestData, catalogCategory, new ArrayList<ProductMarketing>(catalogCategory.getProductMarketings()), true); catalogCategoryViewBean.setProductMarketings(productMarketingViewBeans); int countProduct = catalogCategory.getProductMarketings().size(); for (Iterator<CatalogCategoryViewBean> iterator = catalogCategoryViewBean.getSubCategories() .iterator(); iterator.hasNext();) { CatalogCategoryViewBean subCategoryViewBean = (CatalogCategoryViewBean) iterator.next(); countProduct = countProduct + subCategoryViewBean.getCountProduct(); } catalogCategoryViewBean.setCountProduct(countProduct); List<Asset> assets = catalogCategory.getAssetsIsGlobal(); for (Iterator<Asset> iterator = assets.iterator(); iterator.hasNext();) { Asset asset = (Asset) iterator.next(); catalogCategoryViewBean.getAssets().add(buildAssetViewBean(requestData, asset)); } } catalogCategoryViewBean.setDetailsUrl( backofficeUrlService.generateUrl(BoUrls.MASTER_CATEGORY_DETAILS, requestData, catalogCategory)); catalogCategoryViewBean.setEditUrl( backofficeUrlService.generateUrl(BoUrls.MASTER_CATEGORY_EDIT, requestData, catalogCategory)); } return catalogCategoryViewBean; }
From source file:taximetro.main.java
private void jButtonfinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonfinActionPerformed //Establecer de nuevo parametros de los botones de fin y comienzo carrera. jButtonfin.setEnabled(false);//ww w . java 2 s . com jButtoncomienzo.setEnabled(true); //Parar el contador. cronometro.stop(); //Darle formato HH:mm:ss al resultado del contador. String tiempotexto = DurationFormatUtils.formatDuration(cronometro.getTime(), "HH:mm:ss"); //Guardar la hora de fin de carrera al presionar botn de fin carrera. Calendar tiempo = Calendar.getInstance(zona); //Dar formato a la hora de fin de carrera al presionar el boton de fin. DateFormat formatohoras = DateFormat.getTimeInstance(DateFormat.MEDIUM); String horafincarrera = formatohoras.format(tiempo.getTimeInMillis()); //Dar formato a la fecha. DateFormat formatotiempo = DateFormat.getDateInstance(DateFormat.LONG); String fechatexto = formatotiempo.format(tiempo.getTime()); //Calcular el coste del trayecto, a partir del tiempo del contador. float coste = (cronometro.getTime() / 1000) * (TARIFA / 60); float iva = coste * 0.21F; float costetotal = coste * 1.21F; //Dar formato al coste del trayecto. NumberFormat formatoeuro = NumberFormat.getCurrencyInstance(zona); //Escribir en el area de texto todos los parmetros. jTextAreaticket.append("TICKET:\n \n"); jTextAreaticket.append("=================\n"); jTextAreaticket.append("Ticket N: " + textoticket + " .\n"); jTextAreaticket.append("Fecha:\n" + fechatexto + " .\n\n"); jTextAreaticket.append("Hora de comienzo de carrera: " + horacomienzocarrera + " .\n"); jTextAreaticket.append("Hora de fin de carrera: " + horafincarrera + " .\n"); jTextAreaticket.append("El tiempo del trayecto es: " + tiempotexto + " .\n\n\n"); jTextAreaticket.append("Importe: " + formatoeuro.format(coste) + " .\n"); jTextAreaticket.append("IVA: " + formatoeuro.format(iva) + " .\n"); jTextAreaticket.append("Importe Total: " + formatoeuro.format(costetotal) + " .\n"); }
From source file:org.shengrui.oa.util.UtilDateTime.java
/** * datetime is the String of System.currentTimeMillis() * ??/*from w w w .j av a 2s. co m*/ * */ public static String getDateTimeDisp(String datetime) { if ((datetime == null) || (datetime.equals(""))) return ""; DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); long datel = Long.parseLong(datetime); return formatter.format(new Date(datel)); }