本文整理汇总了Java中java.text.SimpleDateFormat.toPattern方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleDateFormat.toPattern方法的具体用法?Java SimpleDateFormat.toPattern怎么用?Java SimpleDateFormat.toPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.SimpleDateFormat
的用法示例。
在下文中一共展示了SimpleDateFormat.toPattern方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDateInstance
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* <p>Gets a date formatter instance using the specified style, time
* zone and locale.</p>
*
* @param style date style: FULL, LONG, MEDIUM, or SHORT
* @param timeZone optional time zone, overrides time zone of
* formatted date
* @param locale optional locale, overrides system locale
* @return a localized standard date formatter
* @throws IllegalArgumentException if the Locale has no date
* pattern defined
*/
public static synchronized FastDateFormat getDateInstance(int style, TimeZone timeZone, Locale locale) {
Object key = new Integer(style);
if (timeZone != null) {
key = new Pair(key, timeZone);
}
if (locale == null) {
locale = Locale.getDefault();
}
key = new Pair(key, locale);
FastDateFormat format = (FastDateFormat) cDateInstanceCache.get(key);
if (format == null) {
try {
SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateInstance(style, locale);
String pattern = formatter.toPattern();
format = getInstance(pattern, timeZone, locale);
cDateInstanceCache.put(key, format);
} catch (ClassCastException ex) {
throw new IllegalArgumentException("No date pattern for locale: " + locale);
}
}
return format;
}
示例2: getTimeInstance
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* <p>Gets a time formatter instance using the specified style, time
* zone and locale.</p>
*
* @param style time style: FULL, LONG, MEDIUM, or SHORT
* @param timeZone optional time zone, overrides time zone of
* formatted time
* @param locale optional locale, overrides system locale
* @return a localized standard time formatter
* @throws IllegalArgumentException if the Locale has no time
* pattern defined
*/
public static synchronized FastDateFormat getTimeInstance(int style, TimeZone timeZone, Locale locale) {
Object key = new Integer(style);
if (timeZone != null) {
key = new Pair(key, timeZone);
}
if (locale != null) {
key = new Pair(key, locale);
}
FastDateFormat format = (FastDateFormat) cTimeInstanceCache.get(key);
if (format == null) {
if (locale == null) {
locale = Locale.getDefault();
}
try {
SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getTimeInstance(style, locale);
String pattern = formatter.toPattern();
format = getInstance(pattern, timeZone, locale);
cTimeInstanceCache.put(key, format);
} catch (ClassCastException ex) {
throw new IllegalArgumentException("No date pattern for locale: " + locale);
}
}
return format;
}
示例3: getDateTimeInstance
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* <p>Gets a date/time formatter instance using the specified style,
* time zone and locale.</p>
*
* @param dateStyle date style: FULL, LONG, MEDIUM, or SHORT
* @param timeStyle time style: FULL, LONG, MEDIUM, or SHORT
* @param timeZone optional time zone, overrides time zone of
* formatted date
* @param locale optional locale, overrides system locale
* @return a localized standard date/time formatter
* @throws IllegalArgumentException if the Locale has no date/time
* pattern defined
*/
public static synchronized FastDateFormat getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone,
Locale locale) {
Object key = new Pair(new Integer(dateStyle), new Integer(timeStyle));
if (timeZone != null) {
key = new Pair(key, timeZone);
}
if (locale == null) {
locale = Locale.getDefault();
}
key = new Pair(key, locale);
FastDateFormat format = (FastDateFormat) cDateTimeInstanceCache.get(key);
if (format == null) {
try {
SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(dateStyle, timeStyle,
locale);
String pattern = formatter.toPattern();
format = getInstance(pattern, timeZone, locale);
cDateTimeInstanceCache.put(key, format);
} catch (ClassCastException ex) {
throw new IllegalArgumentException("No date time pattern for locale: " + locale);
}
}
return format;
}
示例4: parseValue
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
private Object parseValue(Path<Object> path, Object value) {
if (Date.class.isAssignableFrom(path.getJavaType())) {
try {
SimpleDateFormat dateFormat = this.dateFormat != null ? this.dateFormat : defaultDateFormat;
value = dateFormat.parse(value.toString());
} catch (ParseException e) {
throw new SpecificationException("Illegal date format: " + value + ", required format is " + dateFormat.toPattern());
}
}
return value;
}
示例5: parse
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* Parse the text with the format and locale specified
*
* @param text the text to parse
* @param format the date format, see {@link java.text.SimpleDateFormat} for more information
* @param locale the locale
* @return the parsed date
* @throws ParserException if the text cannot be parsed
*/
public Date parse(String text, String format, Locale locale) throws ParserException {
SimpleDateFormat dateFormat = getDateFormat(format, locale);
try {
return dateFormat.parse(text.trim());
} catch (ParseException e) {
throw new ParserException("Error when parsing date(" + dateFormat.toPattern() + ") from " + text, e);
}
}
示例6: getDateFormat
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* @param length
* the type of date format, e.g. {@link CachingDateFormat#LONG }
* @param locale
* the <code>Locale</code> that will be used to determine the
* date pattern
*
* @see #getDateFormat(String, boolean)
* @see CachingDateFormat#SHORT
* @see CachingDateFormat#MEDIUM
* @see CachingDateFormat#LONG
* @see CachingDateFormat#FULL
*/
public static SimpleDateFormat getDateFormat(int length, Locale locale, boolean lenient)
{
SimpleDateFormat dateFormat = (SimpleDateFormat) CachingDateFormat.getDateInstance(length, locale);
// extract the format string
String pattern = dateFormat.toPattern();
// we have a pattern to use
return getDateFormat(pattern, lenient);
}
示例7: getDateTimeFormat
import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
* @param dateLength
* the type of date format, e.g. {@link CachingDateFormat#LONG }
* @param timeLength
* the type of time format, e.g. {@link CachingDateFormat#LONG }
* @param locale
* the <code>Locale</code> that will be used to determine the
* date pattern
*
* @see #getDateFormat(String, boolean)
* @see CachingDateFormat#SHORT
* @see CachingDateFormat#MEDIUM
* @see CachingDateFormat#LONG
* @see CachingDateFormat#FULL
*/
public static SimpleDateFormat getDateTimeFormat(int dateLength, int timeLength, Locale locale, boolean lenient)
{
SimpleDateFormat dateFormat = (SimpleDateFormat) CachingDateFormat.getDateTimeInstance(dateLength, timeLength, locale);
// extract the format string
String pattern = dateFormat.toPattern();
// we have a pattern to use
return getDateFormat(pattern, lenient);
}