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:DateLocaleServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //Get the client's Locale Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale); String welcome = bundle.getString("Welcome"); String date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(new Date()); //Display the locale response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>" + welcome + "</title></head><body>"); out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>"); out.println(date + "<br /><br />"); java.util.Enumeration e = bundle.getKeys(); while (e.hasMoreElements()) { out.println((String) e.nextElement()); out.println("<br /><br />"); }//from ww w .j a v a 2 s .com out.println("Locale: "); out.println(locale.getLanguage() + "_" + locale.getCountry()); out.println("</body></html>"); }
From source file:com.vityuk.ginger.provider.format.JdkDateUtils.java
private static int createJdkDateStyleCode(DateFormatStyle formatStyle) { switch (formatStyle) { case SHORT://from ww w. j av a 2 s. c o m return DateFormat.SHORT; case MEDIUM: return DateFormat.MEDIUM; case LONG: return DateFormat.LONG; case FULL: return DateFormat.FULL; case DEFAULT: return DateFormat.DEFAULT; default: throw new IllegalArgumentException(); } }
From source file:com.joshlong.esb.springintegration.modules.social.twitter.test.TwitterProducer.java
public String tweet() { Date d = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); return String.format("The time is %s and all is well!", dateFormat.format(d)); }
From source file:org.jboss.tools.openshift.internal.common.ui.utils.DateTimeUtils.java
public static String formatSince(String value, TimeZone timezone) { try {/*w w w . j ava2 s . c o m*/ Date date = parse(value); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL); if (timezone != null) { formatter.setTimeZone(timezone); } return formatter.format(date); } catch (ParseException e) { OpenShiftCommonUIActivator.getDefault().getLogger() .logWarning("Unable to parse format duration value: " + value, e); } return value; }
From source file:TimeUtil.java
public static String windowFormat(long msecs) { Date tDate = new Date(msecs); long now = System.currentTimeMillis(); long diff = now - msecs; // start with the last 24 hours long comp = MS_PER_DAY; // start comparing if (diff < comp) { // it's within the last 24 hours - just return the time DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT); return formatter.format(tDate); }/*from ww w . ja va 2 s.c o m*/ // now expand to another day comp += MS_PER_DAY; if (diff < comp) { // it's within the last 48 hours - just return the time DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT); return "Yesterday " + formatter.format(tDate); } // now up it to a week comp += 5 * MS_PER_DAY; if (diff < comp) { // return the day of the week and the time // get time to be formatted into a calendar GregorianCalendar tCal = new GregorianCalendar(); tCal.setTime(tDate); SimpleDateFormat formatter = new SimpleDateFormat("EEEE"); return formatter.format(tDate); } // just return full date DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); return formatter.format(tDate); }
From source file:Main.java
public void actionPerformed(ActionEvent e) { Locale locale = Locale.getDefault(); Date date = new Date(e.getWhen()); String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date); if (!model.isEmpty()) { model.clear();/* w w w . ja v a 2s .c o m*/ } if (e.getID() == ActionEvent.ACTION_PERFORMED) { model.addElement(" Event Id: ACTION_PERFORMED"); } model.addElement("Time: " + s); String source = e.getSource().getClass().getName(); int mod = e.getModifiers(); StringBuffer buffer = new StringBuffer("Modifiers: "); if ((mod & ActionEvent.ALT_MASK) > 0) { buffer.append("Alt "); } if ((mod & ActionEvent.SHIFT_MASK) > 0) { buffer.append("Shift "); } if ((mod & ActionEvent.META_MASK) > 0) { buffer.append("Meta "); } if ((mod & ActionEvent.CTRL_MASK) > 0) { buffer.append("Ctrl "); } model.addElement(buffer); }
From source file:org.jdal.vaadin.data.converter.DateConverter.java
@Override protected DateFormat getFormat(Locale locale) { if (locale == null) locale = LocaleContextHolder.getLocale(); DateFormat f = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); f.setLenient(false);//from w w w . j a v a 2 s . com return f; }
From source file:org.nuxeo.launcher.info.MessageInfoLogger.java
public void printMessages() { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); for (MessageInfo message : messages) { System.out//from w w w . j ava 2 s . c om .println("[" + dateFormat.format(message.time) + "] " + message.level + " " + message.message); } }
From source file:DateFormatDemo.java
static public void showBothStyles(Locale currentLocale) { Date today;//from w ww.j a va2 s .c o m 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:proyectoprestamos.DatosUsuario.java
/** * Creates new form DatosUsuario/* w w w. j a v a2s .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()); }