类的用途
java.time.format.DateTimeFormatter
使用 DateTimeFormatter 的包
包
描述
日期、时间、瞬间和持续时间的主要 API。
用于除默认 ISO 之外的日历系统的通用 API。
提供类来打印和解析日期和时间。
-
DateTimeFormatter 在 java.time 中的用法
java.time 中的方法,参数类型为 DateTimeFormatter修饰符和类型方法描述LocalDate.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期。LocalDateTime.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期时间。LocalTime.format(DateTimeFormatter formatter) 这次使用指定的格式化程序进行格式化。MonthDay.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化这个月日。OffsetDateTime.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期时间。OffsetTime.format(DateTimeFormatter formatter) 这次使用指定的格式化程序进行格式化。Year.format(DateTimeFormatter formatter) 今年使用指定的格式化程序格式化。YearMonth.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化今年-月份。ZonedDateTime.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期时间。static LocalDateLocalDate.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取LocalDate的实例。static LocalDateTimeLocalDateTime.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取LocalDateTime的实例。static LocalTimeLocalTime.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取LocalTime的实例。static MonthDayMonthDay.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取MonthDay的实例。static OffsetDateTimeOffsetDateTime.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取OffsetDateTime的实例。static OffsetTimeOffsetTime.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取OffsetTime的实例。static YearYear.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取Year的实例。static YearMonthYearMonth.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取YearMonth的实例。static ZonedDateTimeZonedDateTime.parse(CharSequence text, DateTimeFormatter formatter) 使用特定格式化程序从文本字符串中获取ZonedDateTime的实例。 -
DateTimeFormatter 在 java.time.chrono 中的用法
java.time.chrono 中的方法,参数类型为 DateTimeFormatter修饰符和类型方法描述default StringChronoLocalDate.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期。default StringChronoLocalDateTime.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期时间。default StringChronoZonedDateTime.format(DateTimeFormatter formatter) 使用指定的格式化程序格式化此日期时间。 -
DateTimeFormatter 在 java.time.format 中的用法
java.time.format 中的字段声明为 DateTimeFormatter修饰符和类型Field描述static final DateTimeFormatterDateTimeFormatter.BASIC_ISO_DATEISO 日期格式化程序,用于格式化或解析没有偏移量的日期,例如“20111203”。static final DateTimeFormatterDateTimeFormatter.ISO_DATEISO 日期格式化程序,它使用偏移量(如果可用)格式化或解析日期,例如“2011-12-03”或“2011-12-03+01:00”。static final DateTimeFormatterDateTimeFormatter.ISO_DATE_TIME类似 ISO 的日期时间格式化程序,它使用偏移量和区域(如果可用)格式化或解析日期时间,例如 '2011-12-03T10:15:30'、'2011-12-03T10:15:30+01 :00' 或 '2011-12-03T10:15:30+01:00[欧洲/巴黎]'。static final DateTimeFormatterDateTimeFormatter.ISO_INSTANT格式化或解析 UTC 格式的 ISO 即时格式化程序,例如“2011-12-03T10:15:30Z”。static final DateTimeFormatterDateTimeFormatter.ISO_LOCAL_DATEISO 日期格式化程序,用于格式化或解析没有偏移量的日期,例如“2011-12-03”。static final DateTimeFormatterDateTimeFormatter.ISO_LOCAL_DATE_TIMEISO 日期时间格式化程序,用于格式化或解析没有偏移量的日期时间,例如“2011-12-03T10:15:30”。static final DateTimeFormatterDateTimeFormatter.ISO_LOCAL_TIMEISO 时间格式化程序,用于格式化或解析没有偏移量的时间,例如“10:15”或“10:15:30”。static final DateTimeFormatterDateTimeFormatter.ISO_OFFSET_DATEISO 日期格式化程序,用于格式化或解析带有偏移量的日期,例如“2011-12-03+01:00”。static final DateTimeFormatterDateTimeFormatter.ISO_OFFSET_DATE_TIMEISO 日期时间格式化程序,用于格式化或解析带有偏移量的日期时间,例如“2011-12-03T10:15:30+01:00”。static final DateTimeFormatterDateTimeFormatter.ISO_OFFSET_TIMEISO 时间格式化程序,用于格式化或解析带有偏移量的时间,例如“10:15+01:00”或“10:15:30+01:00”。static final DateTimeFormatterDateTimeFormatter.ISO_ORDINAL_DATEISO 日期格式化程序,用于格式化或解析没有偏移量的序号日期,例如“2012-337”。static final DateTimeFormatterDateTimeFormatter.ISO_TIME格式化或解析时间的 ISO 时间格式化程序,带有偏移量(如果可用),例如“10:15”、“10:15:30”或“10:15:30+01:00”。static final DateTimeFormatterDateTimeFormatter.ISO_WEEK_DATEISO 日期格式化程序,用于格式化或解析没有偏移量的基于周的日期,例如“2012-W48-6”。static final DateTimeFormatterDateTimeFormatter.ISO_ZONED_DATE_TIME类似 ISO 的日期时间格式化程序,用于格式化或解析带有偏移量和区域的日期时间,例如“2011-12-03T10:15:30+01:00[Europe/Paris]”。static final DateTimeFormatterDateTimeFormatter.RFC_1123_DATE_TIMERFC-1123 日期时间格式化程序,例如“星期二,2008 年 6 月 3 日 11:05:30 GMT”。java.time.format 中返回 DateTimeFormatter 的方法修饰符和类型方法描述DateTimeFormatter.localizedBy(Locale locale) 返回此格式化程序的副本,其中包含区域设置、日历、区域、十进制样式和/或时区的本地化值,这些值将取代此格式化程序中的值。static DateTimeFormatterDateTimeFormatter.ofLocalizedDate(FormatStyle dateStyle) 返回 ISO 年表的特定于locale的日期格式。static DateTimeFormatterDateTimeFormatter.ofLocalizedDateTime(FormatStyle dateTimeStyle) 返回 ISO 年表的特定于locale的日期时间格式化程序。static DateTimeFormatterDateTimeFormatter.ofLocalizedDateTime(FormatStyle dateStyle, FormatStyle timeStyle) 返回 ISO 年表的特定于区域设置的日期和时间格式。static DateTimeFormatterDateTimeFormatter.ofLocalizedPattern(String requestedTemplate) 创建一个从所请求的 ISO 年表模板派生的特定于区域设置的格式化程序。static DateTimeFormatterDateTimeFormatter.ofLocalizedTime(FormatStyle timeStyle) 返回 ISO 年表的特定于locale的时间格式。static DateTimeFormatter使用指定的模式创建格式化程序。static DateTimeFormatter使用指定的模式和locale创建格式化程序。DateTimeFormatterBuilder.toFormatter()通过使用默认locale创建DateTimeFormatter来完成此构建器。DateTimeFormatterBuilder.toFormatter(Locale locale) 通过使用指定的locale创建DateTimeFormatter来完成此构建器。DateTimeFormatter.withChronology(Chronology chrono) 使用新的重写年表返回此格式化程序的副本。DateTimeFormatter.withDecimalStyle(DecimalStyle decimalStyle) 使用新的 DecimalStyle 返回此格式化程序的副本。DateTimeFormatter.withLocale(Locale locale) 使用新的locale返回此格式化程序的副本。DateTimeFormatter.withResolverFields(TemporalField... resolverFields) 使用一组新的解析器字段返回此格式化程序的副本。DateTimeFormatter.withResolverFields(Set<TemporalField> resolverFields) 使用一组新的解析器字段返回此格式化程序的副本。DateTimeFormatter.withResolverStyle(ResolverStyle resolverStyle) 使用新的解析器样式返回此格式化程序的副本。返回具有新重写区域的此格式化程序的副本。java.time.format 中的方法,参数类型为 DateTimeFormatter修饰符和类型方法描述DateTimeFormatterBuilder.append(DateTimeFormatter formatter) 将格式化程序的所有元素附加到构建器。DateTimeFormatterBuilder.appendOptional(DateTimeFormatter formatter) 将格式化程序附加到构建器,它可以选择格式化/解析。