String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date()); // textView is the TextView view that should display it textView.setText(currentDateTimeString);
/** * Format date for the given locale. JVM timezone is used. */ @Override public String formatDateTime(Locale locale, Date date) { return DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT, locale).format(date); }
private SimpleReporter(MetricRegistry registry, PrintStream output, Locale locale, TimeZone timeZone, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter) { super(registry, "simple-reporter", filter, rateUnit, durationUnit); this.output = output; this.locale = locale; this.dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale); dateFormat.setTimeZone(timeZone); }
TimeZone zone = TimeZone.getTimeZone("America/New_York"); DateFormat format = DateFormat.getDateTimeInstance(); format.setTimeZone(zone); System.out.println(format.format(new Date()));
DateFormat.getDateInstance().format(new Date(0)); DateFormat.getDateTimeInstance().format(new Date(0)); DateFormat.getTimeInstance().format(new Date(0));
@Override public void postSend(Message<?> message, MessageChannel channel, boolean sent) { Object payload = message.getPayload(); assertThat(payload, instanceOf(String.class)); Date date = null; try { date = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT).parse((String) payload); } catch (ParseException e) { fail("fail to parse date"); } assertThat(new Date().compareTo(date), greaterThanOrEqualTo(0)); stopLatch.countDown(); }
if( timeFormat == null ) timeFormat = DateFormat.getTimeInstance( DateFormat.SHORT ); updateTextFieldFormat(); newPanel.add(new JLabel( "Time:" ) ); Date date = new Date(); JFrame frame = new JFrame(); frame.setTitle("Date Time Picker"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DateTimePicker dateTimePicker = new DateTimePicker(); dateTimePicker.setFormats( DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.MEDIUM ) ); dateTimePicker.setTimeFormat( DateFormat.getTimeInstance( DateFormat.MEDIUM ) );
String getPattern(Locale locale) { DateFormat f = null; switch (iType) { case DATE: f = DateFormat.getDateInstance(iDateStyle, locale); break; case TIME: f = DateFormat.getTimeInstance(iTimeStyle, locale); break; case DATETIME: f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale); break; } if (f instanceof SimpleDateFormat == false) { throw new IllegalArgumentException("No datetime pattern for locale: " + locale); } return ((SimpleDateFormat) f).toPattern(); } }
/** * Formats a Date object to return a date and time using the global locale. * * @param date the Date to format. * @return a String representing the date and time. */ public static String formatDateTime(Date date) { if (dateTimeFormat == null) { if (properties != null) { dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, getLocale()); dateTimeFormat.setTimeZone(getTimeZone()); } else { DateFormat instance = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, getLocale()); instance.setTimeZone(getTimeZone()); return instance.format(date); } } return dateTimeFormat.format(date); }
return DateFormat.getDateTimeInstance().format((Date) o); return DateFormat.getTimeInstance().format((Date) o); return DateFormat.getInstance().format((Date) o);
jFormat = DateFormat.getTimeInstance(tok1Style, cacheKey.locale); break; jFormat = DateFormat.getDateInstance(tok1Style, cacheKey.locale); break; int tok2Style = tok.hasMoreTokens() ? parseDateStyleToken(tok.nextToken()) : tok1Style; if (tok2Style != -1) { jFormat = DateFormat.getDateTimeInstance(tok1Style, tok2Style, cacheKey.locale); jFormat.setTimeZone(cacheKey.timeZone);
@Test public void testToDateWithFormat() { Calendar cal = new GregorianCalendar(); cal.clear(); cal.set(1976, 2, 16); // Month is 0-based Date date = StringUtil.toDate("16.03.1976", new SimpleDateFormat("dd.MM.yyyy")); assertNotNull(date); assertEquals(cal.getTime(), date); cal.clear(); cal.set(2004, 4, 13, 23, 51); date = StringUtil.toDate("13.5.04 23:51", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, new Locale("no", "NO"))); assertNotNull(date); assertEquals(cal.getTime(), date); cal.clear(); cal.set(Calendar.HOUR, 1); cal.set(Calendar.MINUTE, 2); date = StringUtil.toDate("1:02 am", DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US)); assertNotNull(date); assertEquals(cal.getTime(), date); }
/** {@inheritDoc} */ @Override public String getStartTimestampFormatted() { return DateFormat.getDateTimeInstance().format(new Date(startTime)); }
DateFormat df = DateFormat.getDateTimeInstance(); df.setTimeZone(TimeZone.getTimeZone("America/New_York")); String ds = df.format(new Date(surfA.dateTime * 1000)); shadowWrite(image, ds, String.format("%f, %f", surfA.lat, surfA.lon)); Graphics2D g2d = image.createGraphics();
dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); } else if (type == FORMAT_TYPE.TIME) { dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); } else { dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale); return dateFormat.format(date);
/** * Format date. * @param d date, may not be null. * @return formatted value. */ private static synchronized String formatDate(final Object d) { Locale currentLocale = Locale.getDefault(); if (currentLocale != dateLocale || dateFormat == null) { dateLocale = currentLocale; dateFormat = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, currentLocale); } return dateFormat.format(d); }
String getPattern(Locale locale) { DateFormat f = null; switch (iType) { case DATE: f = DateFormat.getDateInstance(iDateStyle, locale); break; case TIME: f = DateFormat.getTimeInstance(iTimeStyle, locale); break; case DATETIME: f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale); break; } if (f instanceof SimpleDateFormat == false) { throw new IllegalArgumentException("No datetime pattern for locale: " + locale); } return ((SimpleDateFormat) f).toPattern(); } }
if (dateFormat == null) { if (StringUtils.isEmptyOrWhitespace(pattern)) { dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); } else { dateFormat = new SimpleDateFormat(pattern, locale); dateFormat.setTimeZone(key.timeZone); return dateFormat.format(((Calendar) target).getTime()); return dateFormat.format((java.util.Date)target);
/** * Return a <code>DateFormat<code> for the Locale. * @param locale TODO * @param timeZone TODO * * @return The DateFormat. * @since 1.8.0 */ @Override protected DateFormat getFormat(final Locale locale, final TimeZone timeZone) { DateFormat format = null; if (locale == null) { format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); } else { format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale); } if (timeZone != null) { format.setTimeZone(timeZone); } return format; } }
/** Format a long integer type into a date string. */ private static String formatDate(long date) { DateFormat df = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT); return df.format(new Date(date)); }