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:proyectoprestamos.DatosUsuario.java
/** * Creates new form DatosUsuario/*from www .ja v a 2s . c o m*/ */ public DatosUsuario() { initComponents(); Calendar cal = Calendar.getInstance(); DateFormat formateadorFechaLarga = DateFormat.getDateInstance(DateFormat.MEDIUM); System.out.println(formateadorFechaLarga.format(cal.getTime())); jLabelFecha2.setText(String.valueOf(formateadorFechaLarga.format(cal.getTime()))); DateFormat formateadorHoraCorta = DateFormat.getTimeInstance(DateFormat.SHORT); System.out.println(formateadorHoraCorta.format(cal.getTime())); jLabelHora2.setText(String.valueOf(formateadorHoraCorta.format(cal.getTime()))); setLocationRelativeTo(null); setIconImage(new ImageIcon(getClass().getResource("/imagenes/p.png")).getImage()); }
From source file:DateFormatDemo.java
static public void showBothStyles(Locale currentLocale) { Date today;//from w w w . j ava 2s.c om String result; DateFormat formatter; int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; System.out.println(); System.out.println("Locale: " + currentLocale.toString()); System.out.println(); today = new Date(); for (int k = 0; k < styles.length; k++) { formatter = DateFormat.getDateTimeInstance(styles[k], styles[k], currentLocale); result = formatter.format(today); System.out.println(result); } }
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 ww. j a v a 2 s. co m*/ dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); } return date == null ? "" : dateFormat.format(date); }
From source file:org.nuxeo.ecm.social.mini.message.MiniMessageHelper.java
public static String toJSON(PageProvider<MiniMessage> pageProvider, Locale locale, CoreSession session) { try {/*from w w w . j av a 2 s. co m*/ DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); List<Map<String, Object>> miniMessages = new ArrayList<Map<String, Object>>(); for (MiniMessage miniMessage : pageProvider.getCurrentPage()) { Map<String, Object> o = new HashMap<String, Object>(); o.put("id", miniMessage.getId()); o.put("actor", miniMessage.getActor()); o.put("displayActor", miniMessage.getDisplayActor()); o.put("message", miniMessage.getMessage()); o.put("publishedDate", dateFormat.format(miniMessage.getPublishedDate())); o.put("isCurrentUserMiniMessage", session.getPrincipal().getName().equals(miniMessage.getActor())); miniMessages.add(o); } Map<String, Object> m = new HashMap<String, Object>(); m.put("offset", ((AbstractActivityPageProvider) pageProvider).getNextOffset()); m.put("limit", pageProvider.getCurrentPageSize()); m.put("miniMessages", miniMessages); ObjectMapper mapper = new ObjectMapper(); StringWriter writer = new StringWriter(); mapper.writeValue(writer, m); return writer.toString(); } catch (Exception e) { throw new ClientRuntimeException(e); } }
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);//from ww w .j av a 2 s . c om 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:ClockDemo.java
/** * The init method is called when the browser first starts the applet. It * sets up the Label component and obtains a DateFormat object *///from www . jav a 2s . c o m public void init() { time = new Label(); time.setFont(new Font("helvetica", Font.BOLD, 12)); time.setAlignment(Label.CENTER); setLayout(new BorderLayout()); add(time, BorderLayout.CENTER); timeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM); }
From source file:com.theelix.libreexplorer.DetailsDialog.java
@NonNull @Override//ww w .j av a2 s . c o m public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final LayoutInflater factory = getActivity().getLayoutInflater(); View view = factory.inflate(R.layout.details_dialog, null); ((TextView) view.findViewById(R.id.details_name)).setText(file.getName()); ((TextView) view.findViewById(R.id.details_size)).setText(FileUtilties.getFileSize(file)); SimpleDateFormat dateFormat = ((SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault())); ((TextView) view.findViewById(R.id.details_lastmodified)).setText(dateFormat.format(file.lastModified())); builder.setView(view); return builder.create(); }
From source file:DigitalClock.java
public DigitalClock() { // Set default values for our properties setFormat(DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale())); setUpdateFrequency(1000); // Update once a second // Specify a Swing TransferHandler object to do the dirty work of // copy-and-paste and drag-and-drop for us. This one will transfer // the value of the "time" property. Since this property is read-only // it will allow drags but not drops. setTransferHandler(new TransferHandler("time")); // Since JLabel does not normally support drag-and-drop, we need an // event handler to detect a drag and start the transfer. addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { getTransferHandler().exportAsDrag(DigitalClock.this, e, TransferHandler.COPY); }/*from w w w .j a v a2s . c o m*/ }); // Before we can have a keyboard binding for a Copy command, // the component needs to be able to accept keyboard focus. setFocusable(true); // Request focus when we're clicked on addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { requestFocus(); } }); // Use a LineBorder to indicate when we've got the keyboard focus addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { setBorder(LineBorder.createBlackLineBorder()); } public void focusLost(FocusEvent e) { setBorder(null); } }); // Now bind the Ctrl-C keystroke to a "Copy" command. InputMap im = new InputMap(); im.setParent(getInputMap(WHEN_FOCUSED)); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "Copy"); setInputMap(WHEN_FOCUSED, im); // And bind the "Copy" command to a pre-defined Action that performs // a copy using the TransferHandler we've installed. ActionMap am = new ActionMap(); am.setParent(getActionMap()); am.put("Copy", TransferHandler.getCopyAction()); setActionMap(am); // Create a javax.swing.Timer object that will generate ActionEvents // to tell us when to update the displayed time. Every updateFrequency // milliseconds, this timer will cause the actionPerformed() method // to be invoked. (For non-GUI applications, see java.util.Timer.) timer = new Timer(updateFrequency, new ActionListener() { public void actionPerformed(ActionEvent e) { setText(getTime()); // set label to current time string } }); timer.setInitialDelay(0); // Do the first update immediately timer.start(); // Start timing now! }
From source file:DateUtil.java
/** * Formats given date according to specified locale and <code>DateFormat.MEDIUM</code> style * * @param date Date to convert/*from ww w. j a va2s .c o m*/ * @param locale Locale to use for formatting date * @return String representation of date according to given locale and <code>DateFormat.MEDIUM</code> style * @see java.text.DateFormat * @see java.text.DateFormat#MEDIUM */ public static String formatDate(Date date, Locale locale) { return formatDate(date, locale, DateFormat.MEDIUM); }
From source file:DateFormatDemo.java
static public void showDateStyles(Locale currentLocale) { Date today = new Date(); String result;/*from w w w. ja v a 2 s . co m*/ DateFormat formatter; int[] styles = { DateFormat.DEFAULT, DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; System.out.println(); System.out.println("Locale: " + currentLocale.toString()); System.out.println(); for (int k = 0; k < styles.length; k++) { formatter = DateFormat.getDateInstance(styles[k], currentLocale); result = formatter.format(today); System.out.println(result); } }