| Constructor and Description |
|---|
Formatter() |
| Modifier and Type | Method and Description |
|---|---|
static String |
format(Calendar calendar,
boolean withTime)
将指定Calendar时间格式化为纯中文形式
|
static String |
format(Date date)
按照给定的通配模式 YYYY-MM-DD HH:MM:SS ,将时间格式化成相应的字符串
|
static String |
format(Date date,
boolean isUppercase,
boolean withTime)
格式化为中文日期格式,如果isUppercase为false
则返回:2018年10月24日,否则,返回二〇一八年十月二十四日
|
static String |
format(Date date,
DateFormat format)
根据特定格式格式化日期
|
static String |
format(Date date,
DatePrinter format)
根据特定格式格式化日期
|
static String |
format(Date date,
DateTimeFormatter format)
根据特定格式格式化日期
|
static String |
format(Date date,
String format)
根据特定格式格式化日期
|
static String |
format(LocalDateTime localDateTime)
格式化日期时间
格式 yyyy-MM-dd HH:mm:ss
|
static String |
format(LocalDateTime localDateTime,
String format)
根据特定格式格式化日期
|
static String |
format(long timestamp)
将Unix时间戳转换成日期
|
static String |
format(long timestamp,
String format)
将Unix时间戳转换成日期
|
static long |
format(String date)
将指定的日期转换成Unix时间戳
|
static long |
format(String date,
String format)
将指定的日期转换成Unix时间戳
|
static String |
format(String srcDate,
String srcPattern,
String destPattern)
按照给定的通配模式,格式化成相应的时间字符串
|
static String |
format(TemporalAccessor time,
DateTimeFormatter formatter)
格式化日期时间为指定格式
如果为
Month,调用Enum.toString() |
static String |
format(TemporalAccessor time,
String format)
格式化日期时间为指定格式
如果为
Month,调用Enum.toString() |
static String |
formatBetween(Date beginDate,
Date endDate)
格式化日期间隔输出,精确到毫秒
|
static String |
formatBetween(Date beginDate,
Date endDate,
Fields.Units units)
格式化日期间隔输出
|
static String |
formatBetween(long betweenMs)
格式化日期间隔输出,精确到毫秒
|
static String |
formatBetween(long betweenMs,
Fields.Units units)
格式化日期间隔输出
|
static String |
formatDate(Date date)
格式化日期部分(不包括时间)
格式 yyyy-MM-dd
|
static String |
formatDate(Date date,
boolean isHttp)
格式化日期部分(不包括时间)
格式 yyyy-MM-dd
|
static String |
formatTime(Date date)
格式化时间
格式 HH:mm:ss
|
static String |
getShotName(TimeUnit unit)
获取时长单位简写
|
static SimpleDateFormat |
newSimpleFormat(String pattern)
创建
SimpleDateFormat,注意此对象非线程安全
此对象默认为严格格式模式,即parse时如果格式不正确会报错 |
static SimpleDateFormat |
newSimpleFormat(String pattern,
Locale locale,
TimeZone timeZone)
创建
SimpleDateFormat,注意此对象非线程安全
此对象默认为严格格式模式,即parse时如果格式不正确会报错 |
static String |
parse(Calendar calendar,
boolean withTime)
将指定Calendar时间格式化为纯中文形式
|
static DateTime |
parse(CharSequence text)
将日期字符串转换为
DateTime对象,格式:
yyyy-MM-dd HH:mm:ss
yyyy/MM/dd HH:mm:ss
yyyy.MM.dd HH:mm:ss
yyyy年MM月dd日 HH时mm分ss秒
yyyy-MM-dd
yyyy/MM/dd
yyyy.MM.dd
HH:mm:ss
HH时mm分ss秒
yyyy-MM-dd HH:mm
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSSSSS
yyyyMMddHHmmss
yyyyMMddHHmmssSSS
yyyyMMdd
EEE, dd MMM yyyy HH:mm:ss z
EEE MMM dd HH:mm:ss zzz yyyy
yyyy-MM-dd'T'HH:mm:ss'Z'
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
yyyy-MM-dd'T'HH:mm:ssZ
yyyy-MM-dd'T'HH:mm:ss.SSSZ
|
static Calendar |
parse(CharSequence text,
boolean lenient,
DateParser parser)
使用指定
DateParser解析字符串为Calendar |
static DateTime |
parse(CharSequence text,
DateParser parser,
boolean lenient)
构建DateTime对象
|
static LocalDateTime |
parse(CharSequence text,
String pattern)
构建LocalDateTime对象
|
static DateTime |
parse(String text,
DateFormat format)
构建DateTime对象
|
static DateTime |
parse(String text,
DateParser parser)
构建DateTime对象
|
static Calendar |
parse(String text,
Locale locale,
boolean lenient,
String... pattern)
通过给定的日期格式解析日期时间字符串
传入的日期格式会逐个尝试,直到解析成功,返回
Calendar对象 |
static Calendar |
parse(String text,
Locale locale,
String... pattern)
通过给定的日期格式解析日期时间字符串
传入的日期格式会逐个尝试,直到解析成功,返回
Calendar对象 |
static Calendar |
parse(String text,
String... format)
通过给定的日期格式解析日期时间字符串
传入的日期格式会逐个尝试,直到解析成功,返回
Calendar对象 |
static DateTime |
parse(String text,
String pattern)
将特定格式的日期转换为Date对象
|
static Calendar |
parseByPatterns(String text,
Locale locale,
boolean lenient,
String... pattern)
通过给定的日期格式解析日期时间字符串
传入的日期格式会逐个尝试,直到解析成功,返回
Calendar对象 |
static Calendar |
parseByPatterns(String text,
Locale locale,
String... pattern)
通过给定的日期格式解析日期时间字符串
传入的日期格式会逐个尝试,直到解析成功,返回
Calendar对象 |
static Calendar |
parseByPatterns(String text,
String... pattern)
通过给定的日期格式解析日期时间字符串
传入的日期格式会逐个尝试,直到解析成功,返回
Calendar对象 |
static DateTime |
parseCST(CharSequence text)
解析CST时间,格式:
EEE MMM dd HH:mm:ss z yyyy(例如:Wed Aug 01 00:00:00 CST 2020)
|
static DateTime |
parseDate(String text)
解析日期字符串,忽略时分秒,支持的格式包括:
|
static DateTime |
parseDateTime(String text)
解析日期时间字符串,格式支持:
|
static DateTime |
parseTime(String text)
解析时间,格式HH:mm:ss,默认为1970-01-01
|
static DateTime |
parseTimeToday(String text)
解析时间,格式HH:mm:ss,日期默认为今天
|
static DateTime |
parseUTC(String text)
解析UTC时间,格式:
yyyy-MM-dd'T'HH:mm:ss'Z'
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
yyyy-MM-dd'T'HH:mm:ssZ
yyyy-MM-dd'T'HH:mm:ss.SSSZ
yyyy-MM-dd'T'HH:mm:ss+0800
yyyy-MM-dd'T'HH:mm:ss+08:00
|
public static String format(Date date)
date - 待格式化的时间public static String format(Date date, String format)
date - 被格式化的日期format - 日期格式,常用格式见: Fieldspublic static String format(Date date, DatePrinter format)
date - 被格式化的日期format - DatePrinter 或 FormatBuilderpublic static String format(Date date, DateFormat format)
date - 被格式化的日期format - SimpleDateFormatpublic static String format(Date date, DateTimeFormatter format)
date - 被格式化的日期format - SimpleDateFormat Fields.NORM_DATETIME_FORMATpublic static String format(String srcDate, String srcPattern, String destPattern)
srcDate - 原始时间字符串srcPattern - 原始时间通配符destPattern - 格式化成的时间通配符public static long format(String date)
date - 需要转换的日期 yyyy-MM-dd HH:mm:sspublic static String format(long timestamp)
timestamp - 时间戳public static String format(long timestamp, String format)
timestamp - 时间戳format - 格式public static long format(String date, String format)
date - 需要转换的日期format - 格式public static String format(LocalDateTime localDateTime)
localDateTime - 被格式化的日期public static String format(LocalDateTime localDateTime, String format)
localDateTime - 被格式化的日期format - 日期格式,常用格式见: Fieldspublic static String format(TemporalAccessor time, DateTimeFormatter formatter)
Month,调用Enum.toString()time - TemporalAccessorformatter - 日期格式化器,预定义的格式见:DateTimeFormatterpublic static String format(TemporalAccessor time, String format)
Month,调用Enum.toString()time - TemporalAccessorformat - 日期格式public static String format(Date date, boolean isUppercase, boolean withTime)
date - 被格式化的日期isUppercase - 是否采用大写形式withTime - 是否包含时间部分public static String format(Calendar calendar, boolean withTime)
2018-02-24 12:13:14 转换为 二〇一八年二月二十四日(withTime为false)
2018-02-24 12:13:14 转换为 二〇一八年二月二十四日一十二时一十三分一十四秒(withTime为true)
calendar - CalendarwithTime - 是否包含时间部分public static String formatDate(Date date)
date - 被格式化的日期public static String formatDate(Date date, boolean isHttp)
date - 被格式化的日期isHttp - 是否http格式public static String formatTime(Date date)
date - 被格式化的日期public static String formatBetween(Date beginDate, Date endDate, Fields.Units units)
beginDate - 起始日期endDate - 结束日期units - 级别,按照天、小时、分、秒、毫秒分为5个等级public static String formatBetween(Date beginDate, Date endDate)
beginDate - 起始日期endDate - 结束日期public static String formatBetween(long betweenMs, Fields.Units units)
betweenMs - 日期间隔units - 级别,按照天、小时、分、秒、毫秒分为5个等级public static String formatBetween(long betweenMs)
betweenMs - 日期间隔public static String parse(Calendar calendar, boolean withTime)
2018-02-24 12:13:14 转换为 二〇一八年二月二十四日(withTime为false)
2018-02-24 12:13:14 转换为 二〇一八年二月二十四日一十二时一十三分一十四秒(withTime为true)
calendar - CalendarwithTime - 是否包含时间部分public static DateTime parse(CharSequence text)
DateTime对象,格式:
text - 日期字符串public static LocalDateTime parse(CharSequence text, String pattern)
text - 时间字符串(带格式)pattern - 使用Fields定义的格式public static DateTime parse(String text, DateFormat format)
text - Date字符串format - 格式化器 SimpleDateFormatpublic static DateTime parse(String text, DateParser parser)
text - Date字符串parser - 格式化器,FormatBuilderpublic static DateTime parse(String text, String pattern)
text - 特定格式的日期pattern - 格式,例如yyyy-MM-ddpublic static Calendar parse(String text, String... format)
Calendar对象text - 日期时间字符串,非空format - 需要尝试的日期时间格式数组,非空, 见SimpleDateFormatCalendarpublic static Calendar parse(String text, Locale locale, String... pattern)
Calendar对象text - 日期时间字符串,非空locale - 地区,当为null时使用Locale.getDefault()pattern - 需要尝试的日期时间格式数组,非空, 见SimpleDateFormatCalendarpublic static DateTime parse(CharSequence text, DateParser parser, boolean lenient)
text - Date字符串parser - 格式化器,DateParserlenient - 是否宽容模式public static Calendar parse(String text, Locale locale, boolean lenient, String... pattern)
Calendar对象text - 日期时间字符串,非空locale - 地区,当为null时使用Locale.getDefault()lenient - 日期时间解析是否使用严格模式pattern - 需要尝试的日期时间格式数组,非空CalendarCalendar.isLenient()public static DateTime parseDate(String text)
yyyy-MM-dd yyyy/MM/dd yyyy.MM.dd yyyy年MM月dd日
text - 标准形式的日期字符串public static DateTime parseTime(String text)
text - 标准形式的日期字符串public static DateTime parseDateTime(String text)
yyyy-MM-dd HH:mm:ss yyyy/MM/dd HH:mm:ss yyyy.MM.dd HH:mm:ss yyyy年MM月dd日 HH:mm:ss
text - 标准形式的时间字符串public static DateTime parseTimeToday(String text)
text - 标准形式的日期字符串public static Calendar parse(CharSequence text, boolean lenient, DateParser parser)
DateParser解析字符串为Calendartext - 日期字符串lenient - 是否宽容模式parser - DateParserCalendar,解析失败返回nullpublic static DateTime parseCST(CharSequence text)
text - UTC时间public static DateTime parseUTC(String text)
text - UTC时间public static Calendar parseByPatterns(String text, String... pattern)
Calendar对象text - 日期时间字符串,非空pattern - 需要尝试的日期时间格式数组,非空, 见SimpleDateFormatCalendarpublic static Calendar parseByPatterns(String text, Locale locale, String... pattern)
Calendar对象text - 日期时间字符串,非空locale - 地区,当为null时使用Locale.getDefault()pattern - 需要尝试的日期时间格式数组,非空, 见SimpleDateFormatCalendarpublic static Calendar parseByPatterns(String text, Locale locale, boolean lenient, String... pattern)
Calendar对象text - 日期时间字符串,非空locale - 地区,当为null时使用Locale.getDefault()lenient - 日期时间解析是否使用严格模式pattern - 需要尝试的日期时间格式数组,非空CalendarCalendar.isLenient()public static SimpleDateFormat newSimpleFormat(String pattern)
SimpleDateFormat,注意此对象非线程安全
此对象默认为严格格式模式,即parse时如果格式不正确会报错pattern - 表达式SimpleDateFormatpublic static SimpleDateFormat newSimpleFormat(String pattern, Locale locale, TimeZone timeZone)
SimpleDateFormat,注意此对象非线程安全
此对象默认为严格格式模式,即parse时如果格式不正确会报错pattern - 表达式locale - Locale,null表示默认timeZone - TimeZone,null表示默认SimpleDateFormatCopyright © 2022. All rights reserved.