List of usage examples for java.text DateFormat SHORT
int SHORT
To view the source code for java.text DateFormat SHORT.
Click Source Link
From source file:de.uni_koeln.spinfo.maalr.webapp.controller.AdminController.java
@RequestMapping("/admin/export") public void export(@RequestParam(value = "all", defaultValue = "true") boolean allVersions, @RequestParam(value = "dropKeys", defaultValue = "false") boolean dropKeys, HttpServletResponse response)/* w ww. jav a2s. co m*/ throws IOException, NoDatabaseAvailableException, JAXBException, NoSuchAlgorithmException { response.setContentType("application/zip"); StringBuilder fileName = new StringBuilder(); fileName.append("maalr_db_dump_"); if (allVersions) { fileName.append("all_versions_"); } else { fileName.append("current_versions_"); } if (dropKeys) { fileName.append("anonymized_"); } fileName.append(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date())); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip"); ServletOutputStream out = response.getOutputStream(); service.exportData(allVersions, dropKeys, out, fileName.toString()); }
From source file:op.care.prescription.PnlScheduleDose.java
private void cmbUhrzeitItemStateChanged(ItemEvent e) { // currentSelectedTime = (Date) e.getItem(); lblTimeDose.setText(SYSTools.xx(internalClassID + ".lblTimeDose") + " " + DateFormat.getTimeInstance(DateFormat.SHORT).format(e.getItem()) + " " + SYSTools.xx("misc.msg.Time.short")); }
From source file:net.nosleep.superanalyzer.analysis.views.SummaryView.java
public static Vector createStatPairs(Analysis analysis) { Stat trackStats = analysis.getStats(Analysis.KIND_TRACK, null); String name;//from w w w. j av a 2 s . c o m String value; String description; StringTriple triple; Vector statPairs = new Vector(); name = Misc.getString("TRACK_COUNT"); value = Misc.getFormattedCountAsInt(trackStats.getTrackCount(), Misc.getString("TRACK"), Misc.getString("TRACKS")); description = Misc.getString("TRACK_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("PLAY_COUNT"); value = Misc.getFormattedCountAsInt(trackStats.getPlayCount(), Misc.getString("TRACK"), Misc.getString("TRACKS")) + " " + Misc.getString("PLAYED"); description = Misc.getString("PLAY_COUNT_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("TOTAL_TIME"); value = Misc.getFormattedDuration(trackStats.getTotalTime()); description = Misc.getString("TOTAL_TIME_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("TOTAL_PLAY_TIME"); value = Misc.getFormattedDuration(trackStats.getTotalPlayTime()); description = Misc.getString("TOTAL_PLAY_TIME_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("ARTIST_COUNT"); value = Misc.getFormattedCountAsInt(analysis.getHash(Analysis.KIND_ARTIST).size(), Misc.getString("ARTIST"), Misc.getString("ARTISTS")); description = Misc.getString("ARTIST_COUNT_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("ALBUM_COUNT"); value = Misc.getFormattedCountAsInt(analysis.getHash(Analysis.KIND_ALBUM).size(), Misc.getString("ALBUM"), Misc.getString("ALBUMS")); description = Misc.getString("ALBUM_COUNT_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("GENRE_COUNT"); value = Misc.getFormattedCountAsInt(analysis.getHash(Analysis.KIND_GENRE).size(), Misc.getString("GENRE"), Misc.getString("GENRES")); description = Misc.getString("GENRE_COUNT_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("MOST_SONGS_PLAYED_AT"); int hour = trackStats.getPopularHour(); Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, 0); SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT); value = formatter.format(c.getTime()) + " " + Misc.getString("HOUR_SUFFIX"); description = Misc.getString("MOST_SONGS_PLAYED_AT_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("AVERAGE_TRACK_LENGTH"); value = Misc.getFormattedDuration(trackStats.getAvgLength()); description = Misc.getString("AVERAGE_TRACK_LENGTH_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("AVERAGE_PLAY_COUNT"); value = Misc.getFormattedCount(trackStats.getAvgPlayCount(), Misc.getString("PLAY"), Misc.getString("PLAYS")) + " " + Misc.getString("PER_SONG"); description = Misc.getString("AVERAGE_PLAY_COUNT_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("AVERAGE_ALBUM_COMPLETENESS"); value = Misc.getFormattedPercentage(analysis.getAvgAlbumCompleteness()) + " " + Misc.getString("COMPLETE"); description = Misc.getString("AVERAGE_ALBUM_COMPLETENESS_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("COMPLETE_ALBUMS"); value = Misc.getFormattedPercentage(analysis.getAvgCompleteAlbums()) + " " + Misc.getString("ARE_COMPLETE"); description = Misc.getString("COMPLETE_ALBUMS_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("AVERAGE_BIT_RATE"); value = Misc.getFormattedBitrate(analysis.getAvgBitRate()); description = Misc.getString("AVERAGE_BIT_RATE_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("AVERAGE_FILE_SIZE"); value = Misc.getFormattedByteCount(analysis.getAvgFileSize()); description = Misc.getString("AVERAGE_FILE_SIZE_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("TOTAL_LIBRARY_SIZE"); value = Misc.getFormattedByteCount(analysis.getTotalLibrarySize()); description = Misc.getString("TOTAL_LIBRARY_SIZE_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("ALL_SONGS_PLAYED"); value = Misc.getFormattedPercentage(analysis.getAvgTracksPlayedAtLeastOnce()) + " " + Misc.getString("PLAYED_AT_LEAST_ONCE"); description = Misc.getString("ALL_SONGS_PLAYED_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("COMPILATIONS"); value = Misc.getFormattedPercentage(trackStats.getTrackCompilationPercentage()); description = Misc.getString("COMPILATIONS_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("LIBRARY_AGE"); value = Misc.getFormattedDuration(analysis.getLibraryAge()); description = Misc.getString("LIBRARY_AGE_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); name = Misc.getString("AVERAGE_GROWTH_RATE"); value = Misc.getFormattedCount(analysis.getAverageGrowthRate(), Misc.getString("SONG"), Misc.getString("SONGS")) + "/" + Misc.capitalizeByLocale(Misc.getString("WEEK")); description = Misc.getString("AVERAGE_GROWTH_RATE_TOOLTIP"); triple = new StringTriple(name, value, description); statPairs.add(triple); return statPairs; }
From source file:org.telscenter.sail.webapp.presentation.web.controllers.student.brainstorm.XMLBrainstorm.java
public static String getXMLRevision(Revision revision) { Date timestamp = revision.getTimestamp(); String formattedTime = DateFormat.getTimeInstance(DateFormat.SHORT).format(timestamp); String formattedDate = DateFormat.getDateInstance(DateFormat.MEDIUM).format(timestamp); String xmlDisplayname = ""; if (revision.getDisplayname() != null && !revision.getDisplayname().equals("")) { xmlDisplayname = "<displayname>" + revision.getDisplayname() + "</displayname>"; }//from w w w . j a va 2 s. c om String XMLRevision = "<revision><id>" + revision.getId() + "</id><timestamp>" + formattedTime + " " + formattedDate + "</timestamp>" + xmlDisplayname + "<body>" + StringEscapeUtils.escapeHtml(revision.getBody()) + "</body></revision>"; return XMLRevision; }
From source file:omero.gateway.model.PlateAcquisitionData.java
/** * Returns the label associated to the plate acquisition. * * @return See above.// w ww. ja v a2 s . co m */ public String getLabel() { String name = getName(); if (StringUtils.isNotBlank(name)) { return name; } Timestamp time = getStartTime(); String start = ""; String end = ""; if (time != null) { start = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(time); } String[] values = start.split(" "); String date = ""; String dateEnd = ""; if (values.length > 1) { date = values[0]; start = start.substring(date.length() + 1); } time = getEndTime(); if (time != null) { end = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(time); } values = end.split(" "); if (values.length > 1) { if (!date.equals(values[0])) dateEnd = values[0]; end = end.substring(values[0].length() + 1); } String value = ""; if (start.length() == 0 && end.length() == 0) return DEFAULT_TEXT + getId(); if (date.length() == 0 && end.length() != 0) return dateEnd + " " + end; if (dateEnd.length() == 0) { value = date + " " + start; if (end.length() > 0) value += " - " + end; } else { value = date + " " + start + " - " + dateEnd + " " + end; } if (value.length() > 0) return value; return DEFAULT_TEXT + getId(); }
From source file:ubic.gemma.core.analysis.preprocess.batcheffects.BatchInfoPopulationHelperServiceImpl.java
/** * Apply some heuristics to condense the dates down to batches. For example, we might assume dates very close * together (for example, in the same day or within MAX_GAP_BETWEEN_SAMPLES_TO_BE_SAME_BATCH, and we avoid singleton * batches) are to be treated as the same batch (see implementation for details). * * @param allDates all dates/* w ww . ja va2s. c om*/ * @return map of batch identifiers to dates */ Map<String, Collection<Date>> convertDatesToBatches(Collection<Date> allDates) { List<Date> lDates = new ArrayList<>(allDates); Collections.sort(lDates); Map<String, Collection<Date>> result = new LinkedHashMap<>(); int batchNum = 1; DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); String batchDateString = ""; boolean mergedAnySingletons = false; /* * Iterate over dates */ Date lastDate = null; Date nextDate; for (int i = 0; i < lDates.size(); i++) { Date currentDate = lDates.get(i); if (i < lDates.size() - 1) { nextDate = lDates.get(i + 1); } else { nextDate = null; } if (lastDate == null) { // Start our first batch. batchDateString = this.formatBatchName(batchNum, df, currentDate); result.put(batchDateString, new HashSet<Date>()); result.get(batchDateString).add(currentDate); lastDate = currentDate; continue; } /* * Decide whether we have entered a new batch. * * Rules: * * - Processing on the same day is always considered the same batch. * * - Gaps of less then MAX_GAP_BETWEEN_SAMPLES_TO_BE_SAME_BATCH hours are considered the same batch even if * the day is different. Allows for "overnight running" of batches. * * And then two rules that keep us from having batches with just one sample. Such batches buy us nothing at * all. * * - A "singleton" batch at the end of the series is always combined with the last batch. * * - A "singleton" batch in the middle is combined with either the next or previous batch, whichever is * nearer in time. */ if (this.gapIsLarge(lastDate, currentDate) && result.get(batchDateString).size() > 1) { if (nextDate == null) { /* * We're at the last sample, and it's a singleton. We fall through and allow adding it to the end of * the last batch. */ BatchInfoPopulationHelperServiceImpl.log .warn("Singleton at the end of the series, combining with the last batch: gap is " + String.format("%.2f", (currentDate.getTime() - lastDate.getTime()) / (double) (1000 * 60 * 60 * 24)) + " hours."); mergedAnySingletons = true; } else if (this.gapIsLarge(currentDate, nextDate)) { /* * Then we have a singleton that will be stranded when we go to the next date. Do we combine it * forwards or backwards? We choose the smaller gap. */ long backwards = currentDate.getTime() - lastDate.getTime(); long forwards = nextDate.getTime() - currentDate.getTime(); if (forwards < backwards) { // Start a new batch. BatchInfoPopulationHelperServiceImpl.log .warn("Singleton resolved by waiting for the next batch: gap is " + String.format("%.2f", (nextDate.getTime() - currentDate.getTime()) / (double) (1000 * 60 * 60 * 24)) + " hours."); batchNum++; batchDateString = this.formatBatchName(batchNum, df, currentDate); result.put(batchDateString, new HashSet<Date>()); mergedAnySingletons = true; } else { BatchInfoPopulationHelperServiceImpl.log .warn("Singleton resolved by adding to the last batch: gap is " + String.format("%.2f", (currentDate.getTime() - lastDate.getTime()) / (double) (1000 * 60 * 60 * 24)) + " hours."); // don't start a new batch, fall through. } } else { batchNum++; batchDateString = this.formatBatchName(batchNum, df, currentDate); result.put(batchDateString, new HashSet<Date>()); } } // else we fall through and add the current date to the current batch. // express the constraint that we don't allow batches of size 1, even if we would have normally left it in // its own batch. if (result.get(batchDateString).size() == 1 && this.gapIsLarge(lastDate, currentDate)) { mergedAnySingletons = true; BatchInfoPopulationHelperServiceImpl.log .warn("Stranded singleton automatically being merged into a larger batch"); } result.get(batchDateString).add(currentDate); lastDate = currentDate; } if (mergedAnySingletons && result.size() == 1) { // The implication is that if we didn't have the singleton merging, we would have more than one batch. BatchInfoPopulationHelperServiceImpl.log .warn("Singleton merging resulted in all batches being combined"); } return result; }
From source file:org.openvpms.web.resource.i18n.format.DateFormatter.java
/** * Returns a date-time format.// w w w .ja va 2 s . c o m * * @param edit if {@code true} return a format for editing otherwise * @return a format for viewing date-times. */ public static DateFormat getDateTimeFormat(boolean edit) { DateFormat format; Locale locale = Messages.getLocale(); if (edit) { // specify SHORT style for dates when parsing, so that 2 digit years // are handled correctly format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); } else if (DATE_TIME_VIEW_PATTERN != null) { format = new SimpleDateFormat(DATE_TIME_VIEW_PATTERN, locale); } else { format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale); } return format; }
From source file:com.carser.viamais.entity.Transaction.java
public void generateReceipt(final OutputStream os, final String template) throws IOException, DocumentException { reader = new PdfReader(this.getClass().getResourceAsStream("/receipts/" + template)); stamper = new PdfStamper(reader, os); form = stamper.getAcroFields();/*from w w w . j av a 2 s.c o m*/ brazilLocale = new Locale("pt", "BR"); formatter = NumberFormat.getCurrencyInstance(brazilLocale); // Customer data Customer customer = getCustomer(); form.setField("CUSTOMER_NAME", customer.getName().toUpperCase()); form.setField("CUSTOMER_CPF", StringUtil.formatCPF(customer.getCpf())); form.setField("CUSTOMER_RG", customer.getRg().toUpperCase()); // Addres data Address address = customer.getAddresses().get(0); StringBuilder addressDescription = new StringBuilder(); addressDescription.append(address.getStreet()); addressDescription.append(", " + address.getNumber()); if (address.getComplement() != null) { addressDescription.append(", " + address.getComplement()); } form.setField("CUSTOMER_ADDRESS", addressDescription.toString().toUpperCase()); form.setField("CUSTOMER_DISTRICT", address.getDistrict().toUpperCase()); form.setField("CUSTOMER_CEP", address.getCep()); form.setField("CUSTOMER_CITY", address.getCity().toUpperCase()); form.setField("CUSTOMER_STATE", address.getState().toUpperCase()); List<Phone> phones = customer.getPhones(); for (Phone phone : phones) { String phoneNumber = StringUtil.formatPhone(Long.valueOf(phone.getPrefix() + "" + phone.getNumber())); switch (phone.getType()) { case "Celular": form.setField("CUSTOMER_CELLPHONE", phoneNumber); break; case "Residencial": form.setField("CUSTOMER_PHONE", phoneNumber); break; case "Comercial": form.setField("CUSTOMER_COMPHONE", phoneNumber); break; default: break; } } // Car data Car car = getCar(); form.setField("CAR_MANUFACTURER", car.getModel().getManufacturer().getName().toUpperCase()); form.setField("CAR_MODEL", car.getModel().getName().toUpperCase()); form.setField("CAR_YEAR", car.getYearOfManufacture() + "/" + car.getYearOfModel()); form.setField("CAR_COLOR", car.getColor().toUpperCase()); form.setField("CAR_PLATE", car.getLicensePlate().toUpperCase()); form.setField("CAR_CHASSI", car.getChassi().toUpperCase()); form.setField("CAR_RENAVAM", car.getRenavam().toUpperCase()); // Transaction data form.setField("CAR_DEPOSIT", formatter.format(getDeposit()) + " (" + StringUtil.formatCurrency(getDeposit()) + ")"); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.LONG, brazilLocale); form.setField("CAR_VALUE", formatter.format(getPrice()) + " (" + StringUtil.formatCurrency(getPrice()) + ")"); form.setField("DATE", dateFormatter.format(new Date())); DateFormat deliveryDateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, brazilLocale); DateFormat deliveryTimeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT, brazilLocale); if (getDeliveryDate() != null) { form.setField("DELIVERY_DATE", deliveryDateFormatter.format(getDeliveryDate()) + " " + deliveryTimeFormatter.format(getDeliveryDate())); } if (getKm() != null) { form.setField("DELIVERY_KM", getKm().toString()); } }
From source file:com.google.samples.apps.iosched.util.UIUtils.java
/** * Format and return the given session time and {@link Rooms} values using {@link * Config#CONFERENCE_TIMEZONE}.//from w ww . j a v a 2s.c o m */ public static String formatSessionSubtitle(long intervalStart, long intervalEnd, String roomName, StringBuilder recycle, Context context, boolean shortFormat) { // Determine if the session is in the past long currentTimeMillis = TimeUtils.getCurrentTime(context); boolean conferenceEnded = currentTimeMillis > Config.CONFERENCE_END_MILLIS; boolean sessionEnded = currentTimeMillis > intervalEnd; if (sessionEnded && !conferenceEnded) { return context.getString(R.string.session_finished); } if (roomName == null) { roomName = context.getString(R.string.unknown_room); } if (shortFormat) { TimeZone timeZone = SettingsUtils.getDisplayTimeZone(context); Date intervalStartDate = new Date(intervalStart); SimpleDateFormat shortDateFormat = new SimpleDateFormat("MMM dd"); DateFormat shortTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); shortDateFormat.setTimeZone(timeZone); shortTimeFormat.setTimeZone(timeZone); return shortDateFormat.format(intervalStartDate) + " " + shortTimeFormat.format(intervalStartDate); } else { String timeInterval = formatIntervalTimeString(intervalStart, intervalEnd, recycle, context); return context.getString(R.string.session_subtitle, timeInterval, roomName); } }
From source file:org.sonar.core.i18n.DefaultI18n.java
/** * Format date for the given locale. JVM timezone is used. *//*w w w.j av a 2 s . c o m*/ @Override public String formatDateTime(Locale locale, Date date) { return DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT, locale).format(date); }