本文整理汇总了Java中java.time.format.DateTimeFormatter.ISO_DATE_TIME属性的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatter.ISO_DATE_TIME属性的具体用法?Java DateTimeFormatter.ISO_DATE_TIME怎么用?Java DateTimeFormatter.ISO_DATE_TIME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.time.format.DateTimeFormatter
的用法示例。
在下文中一共展示了DateTimeFormatter.ISO_DATE_TIME属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
public static void main(String[] args) {
DateTimeFormatter formatter1 = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
DateTimeFormatter formatter2 = DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL);
DateTimeFormatter formatter3 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
DateTimeFormatter formatter4 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT);
DateTimeFormatter formatter5 = DateTimeFormatter.BASIC_ISO_DATE;
// 2057-08-11
DateTimeFormatter isoLocalDate = DateTimeFormatter.ISO_LOCAL_DATE;
DateTimeFormatter isoDate = DateTimeFormatter.ISO_DATE;
// 14:30:15.312
DateTimeFormatter isoTime = DateTimeFormatter.ISO_TIME;
DateTimeFormatter isoLocalTime = DateTimeFormatter.ISO_LOCAL_TIME;
// 2050-08-11T14:30:15.312
DateTimeFormatter isoDateTime = DateTimeFormatter.ISO_DATE_TIME;
DateTimeFormatter isoLocaDateTime = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
}
示例2: createDateTimeFormatter
/**
* Create a new {@code DateTimeFormatter} using this factory.
* <p>If no specific pattern or style has been defined,
* the supplied {@code fallbackFormatter} will be used.
* @param fallbackFormatter the fall-back formatter to use when no specific
* factory properties have been set (can be {@code null}).
* @return a new date time formatter
*/
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
DateTimeFormatter dateTimeFormatter = null;
if (StringUtils.hasLength(this.pattern)) {
dateTimeFormatter = DateTimeFormatter.ofPattern(this.pattern);
}
else if (this.iso != null && this.iso != ISO.NONE) {
switch (this.iso) {
case DATE:
dateTimeFormatter = DateTimeFormatter.ISO_DATE;
break;
case TIME:
dateTimeFormatter = DateTimeFormatter.ISO_TIME;
break;
case DATE_TIME:
dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
break;
case NONE:
/* no-op */
break;
default:
throw new IllegalStateException("Unsupported ISO format: " + this.iso);
}
}
else if (this.dateStyle != null && this.timeStyle != null) {
dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
}
else if (this.dateStyle != null) {
dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle);
}
else if (this.timeStyle != null) {
dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle);
}
if (dateTimeFormatter != null && this.timeZone != null) {
dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());
}
return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
示例3: testFormat4System
/**
* 使用系统自带的格式化格式
*/
@Test
public void testFormat4System() {
// 使用系统自带的格式化
DateTimeFormatter isoDateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
DateTimeFormatter isoDateFormat = DateTimeFormatter.ISO_DATE;
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 格式化1
String dateTimeFormat = now.format(isoDateTimeFormatter);
System.out.println(dateTimeFormat);
// 格式化2
String dateFormat = now.format(isoDateFormat);
System.out.println(dateFormat);
}
示例4: applyTemporal
private Object applyTemporal(final TemporalAccessor input, PebbleTemplate self, final Locale locale,
int lineNumber, final String format) throws PebbleException {
final DateTimeFormatter formatter = format != null
? DateTimeFormatter.ofPattern(format, locale)
: DateTimeFormatter.ISO_DATE_TIME;
try {
return new SafeString(formatter.format(input));
} catch (DateTimeException dte) {
throw new PebbleException(dte, String.format("Could not parse the string '%1' into a date.",
input.toString()), lineNumber, self.getName());
}
}