public class FastDateFormat extends Format implements DateParser, DatePrinter
FastDateFormat 是一个线程安全的 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
FULL locale dependent date or time style.
|
static int |
LONG
LONG locale dependent date or time style.
|
static int |
MEDIUM
MEDIUM locale dependent date or time style.
|
static int |
SHORT
SHORT locale dependent date or time style.
|
Modifier | Constructor and Description |
---|---|
protected |
FastDateFormat(String pattern,
TimeZone timeZone,
Locale locale)
构造
|
protected |
FastDateFormat(String pattern,
TimeZone timeZone,
Locale locale,
Date centuryStart)
构造
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
String |
format(Calendar calendar)
Formats a
Calendar object. |
<B extends Appendable> |
format(Calendar calendar,
B buf)
Formats a
Calendar object into the supplied Appendable . |
String |
format(Date date)
使用
GregorianCalendar 格式化 Date |
<B extends Appendable> |
format(Date date,
B buf)
Formats a
Date object into the supplied Appendable using a GregorianCalendar . |
String |
format(long millis)
格式化日期表示的毫秒数
|
<B extends Appendable> |
format(long millis,
B buf)
Formats a millisecond
long value into the supplied Appendable . |
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
static FastDateFormat |
getDateInstance(int style)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getDateInstance(int style,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getDateInstance(int style,
TimeZone timeZone)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getDateInstance(int style,
TimeZone timeZone,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
DateTimeFormatter |
getDateTimeFormatter()
便捷获取 DateTimeFormatter
由于
DatePattern 很大一部分的格式没有提供 DateTimeFormatter ,因此这里提供快捷获取方式 |
static FastDateFormat |
getDateTimeInstance(int dateStyle,
int timeStyle)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getDateTimeInstance(int dateStyle,
int timeStyle,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getDateTimeInstance(int dateStyle,
int timeStyle,
TimeZone timeZone)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getDateTimeInstance(int dateStyle,
int timeStyle,
TimeZone timeZone,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getInstance()
获得 FastDateFormat实例,使用默认格式和地区
|
static FastDateFormat |
getInstance(String pattern)
获得 FastDateFormat 实例,使用默认地区
支持缓存 |
static FastDateFormat |
getInstance(String pattern,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getInstance(String pattern,
TimeZone timeZone)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getInstance(String pattern,
TimeZone timeZone,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
Locale |
getLocale()
获得 日期地理位置
|
int |
getMaxLengthEstimate()
估算生成的日期字符串长度
实际生成的字符串长度小于或等于此值 |
String |
getPattern()
获得日期格式化或者转换的格式
|
static FastDateFormat |
getTimeInstance(int style)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getTimeInstance(int style,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getTimeInstance(int style,
TimeZone timeZone)
获得 FastDateFormat 实例
支持缓存 |
static FastDateFormat |
getTimeInstance(int style,
TimeZone timeZone,
Locale locale)
获得 FastDateFormat 实例
支持缓存 |
TimeZone |
getTimeZone()
获得时区
|
int |
hashCode() |
Date |
parse(String source)
|
Date |
parse(String source,
ParsePosition pos)
|
boolean |
parse(String source,
ParsePosition pos,
Calendar calendar)
根据给定格式更新
Calendar
Upon success, the ParsePosition index is updated to indicate how much of the source text was consumed. |
Object |
parseObject(String source,
ParsePosition pos)
|
String |
toString() |
clone, format, formatToCharacterIterator, parseObject
finalize, getClass, notify, notifyAll, wait, wait, wait
parseObject
public static final int FULL
public static final int LONG
public static final int MEDIUM
public static final int SHORT
protected FastDateFormat(String pattern, TimeZone timeZone, Locale locale)
pattern
- 使用SimpleDateFormat
相同的日期格式timeZone
- 非空时区 TimeZone
locale
- Locale
日期地理位置NullPointerException
- if pattern, timeZone, or locale is null.protected FastDateFormat(String pattern, TimeZone timeZone, Locale locale, Date centuryStart)
pattern
- 使用SimpleDateFormat
相同的日期格式timeZone
- 非空时区 TimeZone
locale
- Locale
日期地理位置centuryStart
- The start of the 100 year period to use as the "default century" for 2 digit year parsing. If centuryStart is null, defaults to now - 80 yearsNullPointerException
- if pattern, timeZone, or locale is null.public static FastDateFormat getInstance()
public static FastDateFormat getInstance(String pattern)
pattern
- 使用SimpleDateFormat
相同的日期格式IllegalArgumentException
- 日期格式问题public static FastDateFormat getInstance(String pattern, TimeZone timeZone)
pattern
- 使用SimpleDateFormat
相同的日期格式timeZone
- 时区TimeZone
IllegalArgumentException
- 日期格式问题public static FastDateFormat getInstance(String pattern, Locale locale)
pattern
- 使用SimpleDateFormat
相同的日期格式locale
- Locale
日期地理位置IllegalArgumentException
- 日期格式问题public static FastDateFormat getInstance(String pattern, TimeZone timeZone, Locale locale)
pattern
- 使用SimpleDateFormat
相同的日期格式timeZone
- 时区TimeZone
locale
- Locale
日期地理位置IllegalArgumentException
- 日期格式问题public static FastDateFormat getDateInstance(int style)
style
- date style: FULL, LONG, MEDIUM, or SHORTpublic static FastDateFormat getDateInstance(int style, Locale locale)
style
- date style: FULL, LONG, MEDIUM, or SHORTlocale
- Locale
日期地理位置public static FastDateFormat getDateInstance(int style, TimeZone timeZone)
style
- date style: FULL, LONG, MEDIUM, or SHORTtimeZone
- 时区TimeZone
public static FastDateFormat getDateInstance(int style, TimeZone timeZone, Locale locale)
public static FastDateFormat getTimeInstance(int style)
style
- time style: FULL, LONG, MEDIUM, or SHORTpublic static FastDateFormat getTimeInstance(int style, Locale locale)
style
- time style: FULL, LONG, MEDIUM, or SHORTlocale
- Locale
日期地理位置public static FastDateFormat getTimeInstance(int style, TimeZone timeZone)
style
- time style: FULL, LONG, MEDIUM, or SHORTtimeZone
- optional time zone, overrides time zone of formatted timepublic static FastDateFormat getTimeInstance(int style, TimeZone timeZone, Locale locale)
style
- time style: FULL, LONG, MEDIUM, or SHORTtimeZone
- optional time zone, overrides time zone of formatted timelocale
- Locale
日期地理位置public static FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle)
dateStyle
- date style: FULL, LONG, MEDIUM, or SHORTtimeStyle
- time style: FULL, LONG, MEDIUM, or SHORTpublic static FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale locale)
dateStyle
- date style: FULL, LONG, MEDIUM, or SHORTtimeStyle
- time style: FULL, LONG, MEDIUM, or SHORTlocale
- Locale
日期地理位置public static FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone)
dateStyle
- date style: FULL, LONG, MEDIUM, or SHORTtimeStyle
- time style: FULL, LONG, MEDIUM, or SHORTtimeZone
- 时区TimeZone
public static FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale)
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
public String format(long millis)
DatePrinter
format
in interface DatePrinter
millis
- 日期毫秒数public String format(Date date)
DatePrinter
GregorianCalendar
格式化 Date
format
in interface DatePrinter
date
- 日期 Date
public String format(Calendar calendar)
DatePrinter
Formats a Calendar
object.
Calendar
format
in interface DatePrinter
calendar
- Calendar
public <B extends Appendable> B format(long millis, B buf)
DatePrinter
Formats a millisecond long
value into the supplied Appendable
.
format
in interface DatePrinter
B
- the Appendable class type, usually StringBuilder or StringBuffer.millis
- the millisecond value to formatbuf
- the buffer to format intopublic <B extends Appendable> B format(Date date, B buf)
DatePrinter
Formats a Date
object into the supplied Appendable
using a GregorianCalendar
.
format
in interface DatePrinter
B
- the Appendable class type, usually StringBuilder or StringBuffer.date
- the date to formatbuf
- the buffer to format intopublic <B extends Appendable> B format(Calendar calendar, B buf)
DatePrinter
Formats a Calendar
object into the supplied Appendable
.
format
in interface DatePrinter
B
- the Appendable class type, usually StringBuilder or StringBuffer.calendar
- the calendar to formatbuf
- the buffer to format intopublic Date parse(String source) throws ParseException
DateParser
parse
in interface DateParser
source
- 日期字符串Date
ParseException
- 转换异常,被转换的字符串格式错误。public Date parse(String source, ParsePosition pos)
DateParser
parse
in interface DateParser
source
- 日期字符串pos
- ParsePosition
Date
public boolean parse(String source, ParsePosition pos, Calendar calendar)
DateParser
Calendar
Upon success, the ParsePosition index is updated to indicate how much of the source text was consumed.
Not all source text needs to be consumed.
Upon parse failure, ParsePosition error index is updated to the offset of the source text which does not match the supplied format.parse
in interface DateParser
source
- 被转换的日期字符串pos
- 定义开始转换的位置,转换结束后更新转换到的位置calendar
- The calendar into which to set parsed fields.public Object parseObject(String source, ParsePosition pos)
DateParser
parseObject
in interface DateParser
parseObject
in class Format
source
- A String
whose beginning should be parsed.pos
- the parse positionjava.util.Date
objectDateFormat.parseObject(String, ParsePosition)
public String getPattern()
DateBasic
getPattern
in interface DateBasic
SimpleDateFormat
兼容的格式public TimeZone getTimeZone()
DateBasic
getTimeZone
in interface DateBasic
TimeZone
public int getMaxLengthEstimate()
public DateTimeFormatter getDateTimeFormatter()
DatePattern
很大一部分的格式没有提供 DateTimeFormatter
,因此这里提供快捷获取方式Copyright © 2024. All rights reserved.