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:FormatTest.java
public FormatTestFrame() { setTitle("FormatTest"); setSize(WIDTH, HEIGHT);// ww w .j a v a2s . c o m JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton); add(buttonPanel, BorderLayout.SOUTH); mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 3)); add(mainPanel, BorderLayout.CENTER); JFormattedTextField intField = new JFormattedTextField(NumberFormat.getIntegerInstance()); intField.setValue(new Integer(100)); addRow("Number:", intField); JFormattedTextField intField2 = new JFormattedTextField(NumberFormat.getIntegerInstance()); intField2.setValue(new Integer(100)); intField2.setFocusLostBehavior(JFormattedTextField.COMMIT); addRow("Number (Commit behavior):", intField2); JFormattedTextField intField3 = new JFormattedTextField( new InternationalFormatter(NumberFormat.getIntegerInstance()) { protected DocumentFilter getDocumentFilter() { return filter; } private DocumentFilter filter = new IntFilter(); }); intField3.setValue(new Integer(100)); addRow("Filtered Number", intField3); JFormattedTextField intField4 = new JFormattedTextField(NumberFormat.getIntegerInstance()); intField4.setValue(new Integer(100)); intField4.setInputVerifier(new FormattedTextFieldVerifier()); addRow("Verified Number:", intField4); JFormattedTextField currencyField = new JFormattedTextField(NumberFormat.getCurrencyInstance()); currencyField.setValue(new Double(10)); addRow("Currency:", currencyField); JFormattedTextField dateField = new JFormattedTextField(DateFormat.getDateInstance()); dateField.setValue(new Date()); addRow("Date (default):", dateField); DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT); format.setLenient(false); JFormattedTextField dateField2 = new JFormattedTextField(format); dateField2.setValue(new Date()); addRow("Date (short, not lenient):", dateField2); try { DefaultFormatter formatter = new DefaultFormatter(); formatter.setOverwriteMode(false); JFormattedTextField urlField = new JFormattedTextField(formatter); urlField.setValue(new URL("http://java.sun.com")); addRow("URL:", urlField); } catch (MalformedURLException e) { e.printStackTrace(); } try { MaskFormatter formatter = new MaskFormatter("###-##-####"); formatter.setPlaceholderCharacter('0'); JFormattedTextField ssnField = new JFormattedTextField(formatter); ssnField.setValue("078-05-1120"); addRow("SSN Mask:", ssnField); } catch (ParseException exception) { exception.printStackTrace(); } JFormattedTextField ipField = new JFormattedTextField(new IPAddressFormatter()); ipField.setValue(new byte[] { (byte) 130, 65, 86, 66 }); addRow("IP Address:", ipField); }
From source file:org.olat.core.util.StringHelper.java
/** * @param date//from ww w . java 2 s.c o m * @param locale * @return formatted date/time */ public static String formatLocaleDateTime(long date, Locale locale) { if (date == -1) return "-"; return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format(new Date(date)); }
From source file:org.olat.core.util.Formatter.java
License:asdf
/** * formats the given date so it is friendly to read * //from w w w . j a va 2 s .co m * @param d the date * @return a String with the formatted date and time */ public String formatDateAndTime(Date d) { if (d == null) return null; DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); df.setLenient(false); String da = df.format(d); return da; }
From source file:org.zkoss.ganttz.LeftTasksTreeRow.java
private LeftTasksTreeRow(IDisabilityConfiguration disabilityConfiguration, Task task, ILeftTasksTreeNavigator leftTasksTreeNavigator, Planner planner) { this.disabilityConfiguration = disabilityConfiguration; this.task = task; this.dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locales.getCurrent()); this.leftTasksTreeNavigator = leftTasksTreeNavigator; this.planner = planner; setUpProperties();/*from ww w .j av a2s . c o m*/ }
From source file:org.nuxeo.ecm.platform.ui.web.component.seam.UICellExcel.java
/** * Converts string value as returned by widget to the target type for an accurate cell format in the XLS/CSV export. * <ul>/*from w ww . j a va2 s. com*/ * <li>If force type is set to "number", convert value to a double (null if empty).</li> * <li>If force type is set to "bool", convert value to a boolean (null if empty).</li> * <li>If force type is set to "date", convert value to a date using most frequent date parsers using the short, * medium, long and full formats and current locale, trying first with time information and after with only date * information. Returns null if date is empty or could not be parsed.</li> * </ul> * * @since 5.6 */ protected Object convertStringToTargetType(String value, String forceType) { if (CellType.number.name().equals(forceType)) { if (StringUtils.isBlank(value)) { return null; } return Double.valueOf(value); } else if (CellType.date.name().equals(forceType)) { if (StringUtils.isBlank(value)) { return null; } Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); int[] formats = { DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; for (int format : formats) { try { return DateFormat.getDateTimeInstance(format, format, locale).parse(value); } catch (ParseException e) { // ignore } try { return DateFormat.getDateInstance(format, locale).parse(value); } catch (ParseException e) { // ignore } } log.warn("Could not convert value to a date instance: " + value); return null; } else if (CellType.bool.name().equals(forceType)) { if (StringUtils.isBlank(value)) { return null; } return Boolean.valueOf(value); } return value; }
From source file:org.eclipse.emf.emfstore.internal.client.ui.controller.UIRevertCommitController.java
private String createDefaultProjectName(ESLocalProject project) { final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); return project.getProjectName() + "@" + format.format(new Date()); //$NON-NLS-1$ }
From source file:com.autentia.intra.jsf.schedule.renderer.ActivityScheduleEntryRenderer.java
protected void renderCompactContent(FacesContext context, ResponseWriter writer, HtmlSchedule schedule, ScheduleDay day, ScheduleEntry entry, boolean selected) throws IOException { StringBuffer text = new StringBuffer(); Date startTime = entry.getStartTime(); if (day.getDayStart().after(entry.getStartTime())) { startTime = day.getDayStart();// www . j ava 2 s . c om } Date endTime = entry.getEndTime(); if (day.getDayEnd().before(entry.getEndTime())) { endTime = day.getDayEnd(); } if (!entry.isAllDay()) { DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT); text.append(format.format(startTime)); if (!startTime.equals(endTime)) { text.append("-"); text.append(format.format(endTime)); } text.append(": "); } text.append(StringUtils.abbreviate(entry.getTitle(), 20)); if (((ActivityScheduleEntry) entry).isBillable()) { writer.startElement(HTML.SPAN_ELEM, schedule); writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "entryBillable"), null); } writer.writeText(text.toString(), null); if (((ActivityScheduleEntry) entry).isBillable()) { writer.endElement(HTML.SPAN_ELEM); } }
From source file:com.autentia.tnt.jsf.schedule.renderer.ExternalActivityScheduleEntryRenderer.java
protected void renderCompactContent(FacesContext context, ResponseWriter writer, HtmlSchedule schedule, ScheduleDay day, ScheduleEntry entry, boolean selected) throws IOException { StringBuffer text = new StringBuffer(); Date startTime = entry.getStartTime(); if (day.getDayStart().after(entry.getStartTime())) { startTime = day.getDayStart();/* ww w . jav a 2s.com*/ } Date endTime = entry.getEndTime(); if (day.getDayEnd().before(entry.getEndTime())) { endTime = day.getDayEnd(); } if (!entry.isAllDay()) { DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT); text.append(format.format(startTime)); if (!startTime.equals(endTime)) { text.append("-"); text.append(format.format(endTime)); } text.append(": "); } text.append(StringUtils.abbreviate(entry.getTitle(), 20)); writer.startElement(HTML.SPAN_ELEM, schedule); writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "externalActivity"), null); writer.writeText(text.toString(), null); writer.endElement(HTML.SPAN_ELEM); }
From source file:org.apache.maven.plugin.doap.DoapUtil.java
/** * Write comments in the DOAP file header * * @param writer not null// w ww.j av a 2 s. c o m */ public static void writeHeader(XMLWriter writer) { XmlWriterUtil.writeLineBreak(writer); XmlWriterUtil.writeCommentLineBreak(writer); XmlWriterUtil.writeComment(writer, StringUtils.repeat("=", REPEAT_EQUALS) + " - DO NOT EDIT THIS FILE! - " + StringUtils.repeat("=", REPEAT_EQUALS)); XmlWriterUtil.writeCommentLineBreak(writer); XmlWriterUtil.writeComment(writer, " "); XmlWriterUtil.writeComment(writer, "Any modifications will be overwritten."); XmlWriterUtil.writeComment(writer, " "); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US); XmlWriterUtil.writeComment(writer, "Generated by Maven Doap Plugin " + getPluginVersion() + " on " + dateFormat.format(new Date(System.currentTimeMillis()))); XmlWriterUtil.writeComment(writer, "See: http://maven.apache.org/plugins/maven-doap-plugin/"); XmlWriterUtil.writeComment(writer, " "); XmlWriterUtil.writeCommentLineBreak(writer); XmlWriterUtil.writeLineBreak(writer); }
From source file:lucee.commons.i18n.FormatUtil.java
public static DateFormat[] getTimeFormats(Locale locale, TimeZone tz, boolean lenient) { String id = "t-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient; DateFormat[] df = formats.get(id); if (df == null) { List<DateFormat> list = new ArrayList<DateFormat>(); list.add(DateFormat.getTimeInstance(DateFormat.FULL, locale)); list.add(DateFormat.getTimeInstance(DateFormat.LONG, locale)); list.add(DateFormat.getTimeInstance(DateFormat.MEDIUM, locale)); list.add(DateFormat.getTimeInstance(DateFormat.SHORT, locale)); add24(list, locale);//from ww w . j a v a2s. co m addCustom(list, locale, FORMAT_TYPE_TIME); df = list.toArray(new DateFormat[list.size()]); for (int i = 0; i < df.length; i++) { df[i].setLenient(lenient); df[i].setTimeZone(tz); } formats.put(id, df); } return df; }