本文整理了Java中java.text.DateFormat.getDateTimeInstance()
方法的一些代码示例,展示了DateFormat.getDateTimeInstance()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateFormat.getDateTimeInstance()
方法的具体详情如下:
包路径:java.text.DateFormat
类名称:DateFormat
方法名:getDateTimeInstance
[英]Returns a DateFormat instance for formatting and parsing dates and time values in the DEFAULT style for the default locale.
[中]返回DateFormat实例,用于以默认语言环境的默认样式格式化和分析日期和时间值。
代码示例来源:origin: stackoverflow.com
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
// textView is the TextView view that should display it
textView.setText(currentDateTimeString);
代码示例来源:origin: SonarSource/sonarqube
/**
* 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);
}
代码示例来源:origin: apache/hbase
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);
}
代码示例来源:origin: stackoverflow.com
TimeZone zone = TimeZone.getTimeZone("America/New_York");
DateFormat format = DateFormat.getDateTimeInstance();
format.setTimeZone(zone);
System.out.println(format.format(new Date()));
代码示例来源:origin: stackoverflow.com
DateFormat.getDateInstance().format(new Date(0));
DateFormat.getDateTimeInstance().format(new Date(0));
DateFormat.getTimeInstance().format(new Date(0));
代码示例来源:origin: spring-projects/spring-integration-samples
@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();
}
代码示例来源:origin: stackoverflow.com
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 ) );
代码示例来源:origin: prestodb/presto
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();
}
}
代码示例来源:origin: igniterealtime/Openfire
/**
* 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);
}
代码示例来源:origin: geoserver/geoserver
return DateFormat.getDateTimeInstance().format((Date) o);
return DateFormat.getTimeInstance().format((Date) o);
return DateFormat.getInstance().format((Date) o);
代码示例来源:origin: org.freemarker/freemarker
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);
代码示例来源:origin: haraldk/TwelveMonkeys
@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);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public String getStartTimestampFormatted() {
return DateFormat.getDateTimeInstance().format(new Date(startTime));
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
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();
代码示例来源:origin: openmrs/openmrs-core
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);
代码示例来源:origin: log4j/log4j
/**
* 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);
}
代码示例来源:origin: joda-time/joda-time
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();
}
}
代码示例来源:origin: thymeleaf/thymeleaf
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);
代码示例来源:origin: commons-beanutils/commons-beanutils
/**
* 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;
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/** 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));
}
内容来源于网络,如有侵权,请联系作者删除!