當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleDateFormat.toPattern方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:39,代碼來源:FastDateFormat.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:FastDateFormat.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:41,代碼來源:FastDateFormat.java

示例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;
}
 
開發者ID:ZhongjunTian,項目名稱:spring-repository-plus,代碼行數:12,代碼來源:WhereSpecification.java

示例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);
  }
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:19,代碼來源:Parsers.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:22,代碼來源:CachingDateFormat.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:24,代碼來源:CachingDateFormat.java


注:本文中的java.text.SimpleDateFormat.toPattern方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。