public class FormatBuilder extends Format implements DateParser, DatePrinter
SimpleDateFormat
实现通过以下静态方法获得此对象:
getInstance(String, TimeZone, Locale)
getDateInstance(int, TimeZone, Locale)
getTimeInstance(int, TimeZone, Locale)
getDateTimeInstance(int, int, TimeZone, Locale)Format.Field| Modifier and Type | Field and Description |
|---|---|
static int |
FULL
完全地区相关的日期或时间样式
|
static int |
LONG
长地区相关的日期或时间样式
|
static int |
MEDIUM
中等地区相关的日期或时间样式
|
static int |
SHORT
短地区相关的日期或时间样式
|
| Modifier | Constructor and Description |
|---|---|
protected |
FormatBuilder(String pattern,
TimeZone timeZone,
Locale locale)
构造
|
protected |
FormatBuilder(String pattern,
TimeZone timeZone,
Locale locale,
Date centuryStart)
构造
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
String |
format(Calendar calendar)
格式化
Calendar 对象 |
<B extends Appendable> |
format(Calendar calendar,
B buf)
将
Calendar对象格式化为提供的Appendable
日历上设置的时区仅用于调整时间偏移。解析器构造期间指定的时区将确定格式化字符串中使用的时区 |
String |
format(Date date)
使用
GregorianCalendar 格式化 Date |
<B extends Appendable> |
format(Date date,
B buf)
使用
GregorianCalendar将Date对象格式化为提供的Appendable |
String |
format(long millis)
格式化日期表示的毫秒数
|
<B extends Appendable> |
format(long millis,
B buf)
将毫秒
long值格式化为提供的Appendable |
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
static FormatBuilder |
getDateInstance(int style)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getDateInstance(int style,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getDateInstance(int style,
TimeZone timeZone)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getDateInstance(int style,
TimeZone timeZone,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getDateTimeInstance(int dateStyle,
int timeStyle)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getDateTimeInstance(int dateStyle,
int timeStyle,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getDateTimeInstance(int dateStyle,
int timeStyle,
TimeZone timeZone)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getDateTimeInstance(int dateStyle,
int timeStyle,
TimeZone timeZone,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getInstance()
获得
FormatBuilder 实例,使用默认格式和地区 |
static FormatBuilder |
getInstance(String pattern)
获得
FormatBuilder 实例,使用默认地区
支持缓存 |
static FormatBuilder |
getInstance(String pattern,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getInstance(String pattern,
TimeZone timeZone)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getInstance(String pattern,
TimeZone timeZone,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
Locale |
getLocale()
获得 日期地理位置
|
int |
getMaxLengthEstimate()
估算生成的日期字符串长度
实际生成的字符串长度小于或等于此值
|
String |
getPattern()
获得日期格式化或者转换的格式
|
static FormatBuilder |
getTimeInstance(int style)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getTimeInstance(int style,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getTimeInstance(int style,
TimeZone timeZone)
获得
FormatBuilder 实例
支持缓存 |
static FormatBuilder |
getTimeInstance(int style,
TimeZone timeZone,
Locale locale)
获得
FormatBuilder 实例
支持缓存 |
TimeZone |
getTimeZone()
获得时区
|
int |
hashCode() |
Date |
parse(String source)
将日期字符串解析并转换为
Date 对象
等价于 DateFormat.parse(String) |
Date |
parse(String source,
ParsePosition pos)
将日期字符串解析并转换为
Date 对象
等价于 DateFormat.parse(String, ParsePosition) |
boolean |
parse(String source,
ParsePosition pos,
Calendar calendar)
根据给定格式转换日期字符串
使用解析的字段更新日历。成功之后,将更新ParsePosition索引,以指示消耗了多少源文本。并不是所有的源文本都需要使用
在解析失败时,ParsePosition错误索引将更新为源文本的偏移量,该偏移量与提供的格式不匹配
|
Object |
parseObject(String source,
ParsePosition pos)
根据
ParsePosition 给定将日期字符串解析并转换为 Date 对象 |
String |
toString() |
clone, format, formatToCharacterIterator, parseObjectfinalize, getClass, notify, notifyAll, wait, wait, waitparseObjectpublic static final int FULL
public static final int LONG
public static final int MEDIUM
public static final int SHORT
protected FormatBuilder(String pattern, TimeZone timeZone, Locale locale)
pattern - 使用SimpleDateFormat 相同的日期格式timeZone - 非空时区 TimeZonelocale - Locale 日期地理位置NullPointerException - 如果模式、时区或区域设置为空protected FormatBuilder(String pattern, TimeZone timeZone, Locale locale, Date centuryStart)
pattern - 使用SimpleDateFormat 相同的日期格式timeZone - 非空时区 TimeZonelocale - Locale 日期地理位置centuryStart - 使用100年周期的开始作为2位数年解析的“默认世纪”。如果centuryStart为空,则默认为- 80年NullPointerException - 如果模式、时区或地区为空.public static FormatBuilder getInstance()
FormatBuilder 实例,使用默认格式和地区FormatBuilderpublic static FormatBuilder getInstance(String pattern)
FormatBuilder 实例,使用默认地区
支持缓存pattern - 使用SimpleDateFormat 相同的日期格式FormatBuilderIllegalArgumentException - 日期格式问题public static FormatBuilder getInstance(String pattern, TimeZone timeZone)
FormatBuilder 实例
支持缓存pattern - 使用SimpleDateFormat 相同的日期格式timeZone - 时区TimeZoneFormatBuilderIllegalArgumentException - 日期格式问题public static FormatBuilder getInstance(String pattern, Locale locale)
FormatBuilder 实例
支持缓存pattern - 使用SimpleDateFormat 相同的日期格式locale - Locale 日期地理位置FormatBuilderIllegalArgumentException - 日期格式问题public static FormatBuilder getInstance(String pattern, TimeZone timeZone, Locale locale)
FormatBuilder 实例
支持缓存pattern - 使用SimpleDateFormat 相同的日期格式timeZone - 时区TimeZonelocale - Locale 日期地理位置FormatBuilderIllegalArgumentException - 日期格式问题public static FormatBuilder getDateInstance(int style)
FormatBuilder 实例
支持缓存style - 日期格式: FULL, LONG, MEDIUM, or SHORTFormatBuilderpublic static FormatBuilder getDateInstance(int style, Locale locale)
FormatBuilder 实例
支持缓存style - 日期格式: FULL, LONG, MEDIUM, or SHORTlocale - Locale 日期地理位置FormatBuilderpublic static FormatBuilder getDateInstance(int style, TimeZone timeZone)
FormatBuilder 实例
支持缓存style - 日期格式: FULL, LONG, MEDIUM, or SHORTtimeZone - 时区TimeZoneFormatBuilderpublic static FormatBuilder getDateInstance(int style, TimeZone timeZone, Locale locale)
FormatBuilder 实例
支持缓存style - 日期格式: FULL, LONG, MEDIUM, or SHORTtimeZone - 时区TimeZonelocale - Locale 日期地理位置FormatBuilderpublic static FormatBuilder getTimeInstance(int style)
FormatBuilder 实例
支持缓存style - 时间格式: FULL, LONG, MEDIUM, or SHORTFormatBuilderpublic static FormatBuilder getTimeInstance(int style, Locale locale)
FormatBuilder 实例
支持缓存style - 时间格式: FULL, LONG, MEDIUM, or SHORTlocale - Locale 日期地理位置FormatBuilderpublic static FormatBuilder getTimeInstance(int style, TimeZone timeZone)
FormatBuilder 实例
支持缓存style - 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone - 可选时区,覆盖格式化时间的时区FormatBuilderpublic static FormatBuilder getTimeInstance(int style, TimeZone timeZone, Locale locale)
FormatBuilder 实例
支持缓存style - 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone - 可选时区,覆盖格式化时间的时区locale - Locale 日期地理位置FormatBuilderpublic static FormatBuilder getDateTimeInstance(int dateStyle, int timeStyle)
FormatBuilder 实例
支持缓存dateStyle - 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle - 时间格式: FULL, LONG, MEDIUM, or SHORTFormatBuilderpublic static FormatBuilder getDateTimeInstance(int dateStyle, int timeStyle, Locale locale)
FormatBuilder 实例
支持缓存dateStyle - 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle - 时间格式: FULL, LONG, MEDIUM, or SHORTlocale - Locale 日期地理位置FormatBuilderpublic static FormatBuilder getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone)
FormatBuilder 实例
支持缓存dateStyle - 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle - 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone - 时区TimeZoneFormatBuilderpublic static FormatBuilder getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale)
FormatBuilder 实例
支持缓存dateStyle - 日期格式: FULL, LONG, MEDIUM, or SHORTtimeStyle - 时间格式: FULL, LONG, MEDIUM, or SHORTtimeZone - 时区TimeZonelocale - Locale 日期地理位置FormatBuilderpublic StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
public String format(long millis)
DatePrinterformat in interface DatePrintermillis - 日期毫秒数public String format(Date date)
DatePrinterGregorianCalendar 格式化 Dateformat in interface DatePrinterdate - 日期 Datepublic String format(Calendar calendar)
DatePrinterCalendar 对象format in interface DatePrintercalendar - Calendarpublic <B extends Appendable> B format(long millis, B buf)
DatePrinterlong值格式化为提供的Appendableformat in interface DatePrinterB - 附加类类型,通常是StringBuilder或StringBuffermillis - 要格式化的毫秒值buf - 要格式化为的缓冲区public <B extends Appendable> B format(Date date, B buf)
DatePrinterGregorianCalendar将Date对象格式化为提供的Appendableformat in interface DatePrinterB - 附加类类型,通常是StringBuilder或StringBufferdate - 格式的日期buf - 要格式化为的缓冲区public <B extends Appendable> B format(Calendar calendar, B buf)
DatePrinterCalendar对象格式化为提供的Appendable
日历上设置的时区仅用于调整时间偏移。解析器构造期间指定的时区将确定格式化字符串中使用的时区format in interface DatePrinterB - 附加类类型,通常是StringBuilder或StringBuffercalendar - 要格式化的日历buf - 要格式化为的缓冲区public Date parse(String source) throws ParseException
DateParserDate 对象
等价于 DateFormat.parse(String)parse in interface DateParsersource - 日期字符串DateParseException - 转换异常,被转换的字符串格式错误public Date parse(String source, ParsePosition pos)
DateParserDate 对象
等价于 DateFormat.parse(String, ParsePosition)parse in interface DateParsersource - 日期字符串pos - ParsePositionDatepublic boolean parse(String source, ParsePosition pos, Calendar calendar)
DateParserparse in interface DateParsersource - 被转换的日期字符串pos - 定义开始转换的位置,转换结束后更新转换到的位置calendar - 用于设置已解析字段的日历public Object parseObject(String source, ParsePosition pos)
DateParserParsePosition 给定将日期字符串解析并转换为 Date 对象parseObject in interface DateParserparseObject in class Formatsource - 应该解析其开头的字符串pos - 解析的位置DateFormat.parseObject(String, ParsePosition)public String getPattern()
FormattergetPattern in interface FormatterSimpleDateFormat兼容的格式public TimeZone getTimeZone()
FormattergetTimeZone in interface FormatterTimeZonepublic int getMaxLengthEstimate()
Copyright © 2020. All rights reserved.