亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? datetimeconverter.java

?? 這是一個有關common beanutils 的源碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.beanutils.converters;

import java.util.Date;
import java.util.Locale;
import java.util.Calendar;
import java.util.TimeZone;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
import org.apache.commons.beanutils.ConversionException;

/**
 * {@link org.apache.commons.beanutils.Converter} implementaion
 * that handles conversion to and from <b>date/time</b> objects.
 * <p>
 * This implementation handles conversion for the following
 * <i>date/time</i> types.
 * <ul>
 *     <li><code>java.util.Date</code></li>
 *     <li><code>java.util.Calendar</code></li>
 *     <li><code>java.sql.Date</code></li>
 *     <li><code>java.sql.Time</code></li>
 *     <li><code>java.sql.Timestamp</code></li>
 * </ul>
 *
 * <h3>String Conversions (to and from)</h3>
 * This class provides a number of ways in which date/time
 * conversions to/from Strings can be achieved:
 * <ul>
 *    <li>Using the SHORT date format for the default Locale, configure using:</li>
 *        <ul>
 *           <li><code>setUseLocaleFormat(true)</code></li>
 *        </ul>
 *    <li>Using the SHORT date format for a specified Locale, configure using:</li>
 *        <ul>
 *           <li><code>setLocale(Locale)</code></li>
 *        </ul>
 *    <li>Using the specified date pattern(s) for the default Locale, configure using:</li>
 *        <ul>
 *           <li>Either <code>setPattern(String)</code> or
 *                      <code>setPatterns(String[])</code></li>
 *        </ul>
 *    <li>Using the specified date pattern(s) for a specified Locale, configure using:</li>
 *        <ul>
 *           <li><code>setPattern(String)</code> or
 *                    <code>setPatterns(String[]) and...</code></li>
 *           <li><code>setLocale(Locale)</code></li>
 *        </ul>
 *    <li>If none of the above are configured the
 *        <code>toDate(String)</code> method is used to convert
 *        from String to Date and the Dates's
 *        <code>toString()</code> method used to convert from
 *        Date to String.</li>
 * </ul>
 *
 * <p>
 * The <b>Time Zone</b> to use with the date format can be specified
 * using the <code>setTimeZone()</code> method.
 *
 * @version $Revision: 640131 $ $Date: 2008-03-23 02:10:31 +0000 (Sun, 23 Mar 2008) $
 * @since 1.8.0
 */
public abstract class DateTimeConverter extends AbstractConverter {

    private String[] patterns;
    private String displayPatterns;
    private Locale locale;
    private TimeZone timeZone;
    private boolean useLocaleFormat;


    // ----------------------------------------------------------- Constructors

    /**
     * Construct a Date/Time <i>Converter</i> that throws a
     * <code>ConversionException</code> if an error occurs.
     */
    public DateTimeConverter() {
        super();
    }

    /**
     * Construct a Date/Time <i>Converter</i> that returns a default
     * value if an error occurs.
     *
     * @param defaultValue The default value to be returned
     * if the value to be converted is missing or an error
     * occurs converting the value.
     */
    public DateTimeConverter(Object defaultValue) {
        super(defaultValue);
    }


    // --------------------------------------------------------- Public Methods

    /**
     * Indicate whether conversion should use a format/pattern or not.
     *
     * @param useLocaleFormat <code>true</code> if the format
     * for the locale should be used, otherwise <code>false</code>
     */
    public void setUseLocaleFormat(boolean useLocaleFormat) {
        this.useLocaleFormat = useLocaleFormat;
    }

    /**
     * Return the Time Zone to use when converting dates
     * (or <code>null</code> if none specified.
     *
     * @return The Time Zone.
     */
    public TimeZone getTimeZone() {
        return timeZone;
    }

    /**
     * Set the Time Zone to use when converting dates.
     *
     * @param timeZone The Time Zone.
     */
    public void setTimeZone(TimeZone timeZone) {
        this.timeZone = timeZone;
    }

    /**
     * Return the Locale for the <i>Converter</i>
     * (or <code>null</code> if none specified).
     *
     * @return The locale to use for conversion
     */
    public Locale getLocale() {
        return locale;
    }

    /**
     * Set the Locale for the <i>Converter</i>.
     *
     * @param locale The Locale.
     */
    public void setLocale(Locale locale) {
        this.locale = locale;
        setUseLocaleFormat(true);
    }

    /**
     * Set a date format pattern to use to convert
     * dates to/from a <code>java.lang.String</code>.
     *
     * @see SimpleDateFormat
     * @param pattern The format pattern.
     */
    public void setPattern(String pattern) {
        setPatterns(new String[] {pattern});
    }

    /**
     * Return the date format patterns used to convert
     * dates to/from a <code>java.lang.String</code>
     * (or <code>null</code> if none specified).
     *
     * @see SimpleDateFormat
     * @return Array of format patterns.
     */
    public String[] getPatterns() {
        return patterns; 
    }

    /**
     * Set the date format patterns to use to convert
     * dates to/from a <code>java.lang.String</code>.
     *
     * @see SimpleDateFormat
     * @param patterns Array of format patterns.
     */
    public void setPatterns(String[] patterns) {
        this.patterns = patterns;
        if (patterns != null && patterns.length > 1) {
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < patterns.length; i++) {
                if (i > 0) {
                    buffer.append(", ");
                }
                buffer.append(patterns[i]);
            }
            displayPatterns = buffer.toString();
        }
        setUseLocaleFormat(true);
    }

    // ------------------------------------------------------ Protected Methods

    /**
     * Convert an input Date/Calendar object into a String.
     * <p>
     * <b>N.B.</b>If the converter has been configured to with
     * one or more patterns (using <code>setPatterns()</code>), then
     * the first pattern will be used to format the date into a String.
     * Otherwise the default <code>DateFormat</code> for the default locale
     * (and <i>style</i> if configured) will be used.
     *
     * @param value The input value to be converted
     * @return the converted String value.
     * @throws Throwable if an error occurs converting to a String
     */
    protected String convertToString(Object value) throws Throwable {

        Date date = null;
        if (value instanceof Date) {
            date = (Date)value;
        } else if (value instanceof Calendar) {
            date = ((Calendar)value).getTime();
        } else if (value instanceof Long) {
            date = new Date(((Long)value).longValue());
        }

        String result = null;
        if (useLocaleFormat && date != null) {
            DateFormat format = null;
            if (patterns != null && patterns.length > 0) {
                format = getFormat(patterns[0]);
            } else {
                format = getFormat(locale, timeZone);
            }
            logFormat("Formatting", format);
            result = format.format(date);
            if (log().isDebugEnabled()) {
                log().debug("    Converted  to String using format '" + result + "'");
            }
        } else {
            result = value.toString();
            if (log().isDebugEnabled()) {
                log().debug("    Converted  to String using toString() '" + result + "'");
             }
        }
        return result;
    }

    /**
     * Convert the input object into a Date object of the
     * specified type.
     * <p>
     * This method handles conversions between the following
     * types:
     * <ul>
     *     <li><code>java.util.Date</code></li>
     *     <li><code>java.util.Calendar</code></li>
     *     <li><code>java.sql.Date</code></li>
     *     <li><code>java.sql.Time</code></li>
     *     <li><code>java.sql.Timestamp</code></li>
     * </ul>
     *
     * It also handles conversion from a <code>String</code> to
     * any of the above types.
     * <p>
     *
     * For <code>String</code> conversion, if the converter has been configured
     * with one or more patterns (using <code>setPatterns()</code>), then
     * the conversion is attempted with each of the specified patterns.
     * Otherwise the default <code>DateFormat</code> for the default locale
     * (and <i>style</i> if configured) will be used.
     *
     * @param targetType Data type to which this value should be converted.
     * @param value The input value to be converted.
     * @return The converted value.
     * @throws Exception if conversion cannot be performed successfully
     */
    protected Object convertToType(Class targetType, Object value) throws Exception {

        Class sourceType = value.getClass();

        // Handle java.sql.Timestamp
        if (value instanceof java.sql.Timestamp) {

            // ---------------------- JDK 1.3 Fix ----------------------
            // N.B. Prior to JDK 1.4 the Timestamp's getTime() method
            //      didn't include the milliseconds. The following code
            //      ensures it works consistently accross JDK versions
            java.sql.Timestamp timestamp = (java.sql.Timestamp)value;
            long timeInMillis = ((timestamp.getTime() / 1000) * 1000);
            timeInMillis += timestamp.getNanos() / 1000000;
            // ---------------------- JDK 1.3 Fix ----------------------
            return toDate(targetType, timeInMillis);
        }

        // Handle Date (includes java.sql.Date & java.sql.Time)
        if (value instanceof Date) {
            Date date = (Date)value;
            return toDate(targetType, date.getTime());
        }

        // Handle Calendar
        if (value instanceof Calendar) {
            Calendar calendar = (Calendar)value;
            return toDate(targetType, calendar.getTime().getTime());
        }

        // Handle Long
        if (value instanceof Long) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人免费视频网站高清观看视频| 久久国产精品一区二区| 国产精品 日产精品 欧美精品| 91精品国产91久久久久久一区二区| 亚洲与欧洲av电影| 在线看国产一区| 亚洲欧美色图小说| 99精品久久只有精品| 国产精品毛片a∨一区二区三区| 国产在线看一区| 26uuu国产电影一区二区| 久久97超碰国产精品超碰| 欧美mv和日韩mv的网站| 激情综合色丁香一区二区| 精品久久久久久无| 国产一区啦啦啦在线观看| 久久噜噜亚洲综合| 国产一区二区三区美女| 国产欧美精品一区| 波多野结衣视频一区| 亚洲视频资源在线| 日本精品一区二区三区高清 | 狠狠色丁香久久婷婷综合_中| 日韩美一区二区三区| 久久精品国产99久久6| 26uuu亚洲综合色欧美| 国产成人精品免费| 中文字幕在线一区免费| 在线欧美日韩精品| 午夜精品123| 久久综合av免费| av在线免费不卡| 亚洲黄色在线视频| 欧美电影在线免费观看| 精品亚洲aⅴ乱码一区二区三区| 久久久午夜电影| 99精品1区2区| 亚洲大片免费看| 欧美成人精品福利| 成人黄色av网站在线| 一区二区三区四区激情| 91 com成人网| 国产高清久久久久| 亚洲一区二区在线观看视频| 337p亚洲精品色噜噜| 国产麻豆精品95视频| 最新中文字幕一区二区三区| 欧美性xxxxxx少妇| 久久精品国产第一区二区三区| 国产精品三级在线观看| 在线观看一区日韩| 美女视频黄久久| 国产精品家庭影院| 91精品国产91热久久久做人人 | 成人动漫一区二区三区| 亚洲成a人v欧美综合天堂下载| 日韩欧美成人一区二区| 国产mv日韩mv欧美| 午夜视频在线观看一区二区| 欧美成人精品福利| 一本到不卡免费一区二区| 日韩成人dvd| 成人欧美一区二区三区小说| 欧美日产国产精品| 丁香激情综合五月| 五月开心婷婷久久| 国产精品天干天干在线综合| 欧美人妖巨大在线| 成人性生交大片免费看在线播放| 亚洲成人动漫av| 国产欧美日韩不卡免费| 欧美电影在哪看比较好| 成人黄色大片在线观看| 美女国产一区二区三区| 亚洲视频综合在线| 精品国产第一区二区三区观看体验| 91蜜桃免费观看视频| 精一区二区三区| 亚洲永久免费av| 日本美女一区二区| 国产69精品久久99不卡| 亚洲第一激情av| 欧美国产日韩一二三区| 91精品国产91久久久久久一区二区| 成人app软件下载大全免费| 日本v片在线高清不卡在线观看| 中文字幕一区二区三区在线观看| 欧美一区二区久久久| caoporm超碰国产精品| 久久99九九99精品| 午夜伊人狠狠久久| 亚洲天堂网中文字| 久久久精品黄色| 91精品国产综合久久小美女| 91免费国产在线| 国产不卡在线播放| 久久99九九99精品| 日韩在线一区二区三区| 亚洲精品视频免费看| 国产婷婷一区二区| 日韩欧美一区二区不卡| 欧美在线观看视频在线| 91在线无精精品入口| 国产精品白丝av| 麻豆精品视频在线| 亚欧色一区w666天堂| 亚洲欧美日韩综合aⅴ视频| 国产免费成人在线视频| 精品国产露脸精彩对白| 日韩美女一区二区三区四区| 欧美精品精品一区| 欧美午夜理伦三级在线观看| 91视频观看视频| 丁香婷婷综合五月| 国产一区二区精品久久99| 美国毛片一区二区三区| 午夜精品影院在线观看| 亚洲一区二区综合| 一区二区三区资源| 亚洲欧美视频在线观看视频| 中文字幕五月欧美| 中文字幕乱码日本亚洲一区二区 | 欧美亚洲综合在线| 色婷婷激情综合| 91亚洲国产成人精品一区二区三 | 精品国产百合女同互慰| 日韩欧美国产精品| 欧美刺激午夜性久久久久久久| 日韩一级黄色大片| 日韩欧美电影在线| 欧美成人bangbros| 日韩一级片在线播放| 欧美白人最猛性xxxxx69交| 日韩欧美国产一区在线观看| 日韩一级二级三级| 日韩欧美国产综合| 精品久久国产97色综合| 精品福利一二区| 精品国产免费人成电影在线观看四季 | 奇米色777欧美一区二区| 日韩黄色在线观看| 免费成人美女在线观看| 精品在线免费视频| 国产精品中文字幕欧美| 国产.欧美.日韩| 91小视频免费看| 欧美日韩午夜影院| 日韩视频在线你懂得| 欧美大片在线观看| 久久久久国产成人精品亚洲午夜| 欧美国产日韩一二三区| 亚洲免费成人av| 亚洲一区二区三区爽爽爽爽爽| 亚洲第一主播视频| 亚洲va中文字幕| 蜜桃av噜噜一区| 男女男精品视频网| 国产成人福利片| 91啪亚洲精品| 欧美日韩国产经典色站一区二区三区| 在线不卡中文字幕| 久久这里只有精品视频网| 国产精品国产自产拍高清av| 亚洲激情校园春色| 午夜一区二区三区视频| 久久精品国产99国产精品| 成人丝袜18视频在线观看| 日本韩国精品在线| 91精品国产乱码久久蜜臀| 国产无一区二区| 亚洲综合小说图片| 卡一卡二国产精品| 本田岬高潮一区二区三区| 欧美性三三影院| 日韩欧美成人一区二区| 国产女主播在线一区二区| 亚洲美女淫视频| 秋霞电影网一区二区| 丰满少妇久久久久久久| 在线免费一区三区| 久久天天做天天爱综合色| 亚洲另类中文字| 久久超碰97中文字幕| k8久久久一区二区三区| 欧美一区二区三区播放老司机| 中文字幕高清不卡| 日本亚洲一区二区| 成人理论电影网| 91精品国模一区二区三区| 国产精品久线在线观看| 麻豆免费看一区二区三区| 99国产精品国产精品毛片| 日韩一区二区免费电影| 中文字幕五月欧美| 久久99精品一区二区三区三区| 色综合久久久久网| 久久综合国产精品| 亚洲电影在线免费观看| 国产成人福利片| 91精品国产入口在线|