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:ispok.converter.BirthDateConverter.java
@Override public Object getAsObject(FacesContext fc, UIComponent uic, String string) { logger.trace("Entering getAsObject()"); Locale locale = fc.getViewRoot().getLocale(); ResourceBundle rb = ResourceBundle.getBundle("ispok/pres/inter/ispok", locale); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); SimpleDateFormat sdf = (SimpleDateFormat) df; String pattern = sdf.toPattern(); String localPattern = sdf.toLocalizedPattern(); logger.debug("pattern: {}", pattern); logger.debug("localized pattern: {}", localPattern); Date date;//w w w . j a v a 2 s .c o m try { date = new SimpleDateFormat(pattern).parse(string); } catch (ParseException ex) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "invalid date", pattern); throw new ConverterException(msg); } if (date.after(new Date())) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, rb.getString("birthdate_invalid"), rb.getString("birthdate_valid_future")); throw new ConverterException(msg); } Calendar c = Calendar.getInstance(); c.set(1850, 1, 1); if (date.before(c.getTime())) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, rb.getString("birthdate_invalid"), rb.getString("birthdate_valid_past")); throw new ConverterException(msg); } return date; }
From source file:org.openmrs.util.Format.java
public static String format(Date date, Locale locale, FORMAT_TYPE type) { log.debug("Formatting date: " + date + " with locale " + locale); DateFormat dateFormat = null; if (type == FORMAT_TYPE.TIMESTAMP) { dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); } else if (type == FORMAT_TYPE.TIME) { dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); } else {//from w w w. j a v a2s.c om dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); } return date == null ? "" : dateFormat.format(date); }
From source file:TimeViewer.java
protected void refreshTable() { int style = DateFormat.SHORT; DateFormat parser = DateFormat.getTimeInstance(style); selectedDate = new Date(); tableModel.fireTableDataChanged();// ww w.j a va2s. c om }
From source file:lucee.commons.i18n.FormatUtil.java
public static DateFormat[] getDateTimeFormats(Locale locale, TimeZone tz, boolean lenient) { String id = "dt-" + locale.hashCode() + "-" + tz.getID() + "-" + lenient; DateFormat[] df = formats.get(id); if (df == null) { List<DateFormat> list = new ArrayList<DateFormat>(); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale)); list.add(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale)); add24(list, locale);/*w w w . j ava 2 s . co m*/ addCustom(list, locale, FORMAT_TYPE_DATE_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; }
From source file:de.interseroh.report.formatters.TimeFormatter.java
protected DateFormat getFormatterInstance(Locale locale) { return DateFormat.getTimeInstance(DateFormat.SHORT, locale); }
From source file:de.interseroh.report.formatters.DateFormatter.java
@Override protected DateFormat getFormatterInstance(Locale locale) { return DateFormat.getDateInstance(DateFormat.SHORT, locale); }
From source file:de.interseroh.report.formatters.TimestampFormatter.java
@Override protected DateFormat getFormatterInstance(Locale locale) { return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); }
From source file:jgnash.ui.commodity.SecurityItemLabelGenerator.java
/** * Creates an item label generator using the default date and number * formats.//from w w w . jav a2 s . c om * @param node SecurityNode to base format on */ public SecurityItemLabelGenerator(final SecurityNode node) { this(DateFormat.getDateInstance(DateFormat.SHORT), CommodityFormat.getShortNumberFormat(node.getReportedCurrencyNode())); }
From source file:com.sun.utils.StatusFragment.java
public void addMessage(String message) { DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT); message = format.format(new Date()) + " - " + message; messages.add(message);//from w w w . jav a2 s . co m while (messages.size() > LIMIT) { messages.removeFirst(); } notifyAdapters(); }
From source file:net.sf.housekeeper.swing.util.BoundComponentFactory.java
/** * Creates a JSpinner whose value is bound to the given ValueModel. This * means, that the value of the spinner and the value of the ValueModel are * synchronized bidirectionally. Additionally, the spinner uses * the current locale's short format for displaying a date. * // ww w . jav a 2 s. co m * @param valueModel the model that provides the value. Must not be null and * must provide {@link Date}objects. * @return A spinner whose value is bound to <code>valueModel</code>. */ public static JSpinner createDateSpinner(final ValueModel valueModel) { assert valueModel != null : "Parameter valueModel must not be null"; assert valueModel.getValue().getClass() .equals(Date.class) : "valueModel must provide Date objects as values"; final SpinnerDateModel model = new SpinnerDateModelAdapter(valueModel); //Need to truncate the current date for correct spinner operation model.setStart(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); model.setCalendarField(Calendar.DAY_OF_MONTH); final JSpinner spinner = new JSpinner(model); //Set the spinner's editor to use the current locale's short date // format final SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT); final String formatPattern = dateFormat.toPattern(); spinner.setEditor(new JSpinner.DateEditor(spinner, formatPattern)); return spinner; }