jdbc-mysql基礎 util.date 和 sql.date 的toString方法是不同的

來源:互聯網
上載者:User

標籤:new   esc   time   escape   rar   sprintf   .sql   stat   available   

禮悟:
     好好學習多思考,尊師重道存感恩。葉見尋根三二一,江河湖海同一體。
          虛懷若穀良心主,願行無悔給最苦。讀書鍛煉強身心,誠勸且行且珍惜。

 

 

                             javaSE:8
                                    os:windows7 x64
                                   ide:MyEclipse 2017



代碼

package com.jizuiku.jdbc;/** *  *  * @author 給最苦 * @version V17.11.08 */public class UtilDateToSqlDate {public static void main(String[] args) {java.util.Date uDate = new java.util.Date();System.out.println(uDate);// 進行轉換java.sql.Date sDate = new java.sql.Date(uDate.getTime());System.out.println(sDate);}}

 

效果

 

 

util.date的toString方法的原始碼

    /**     * Converts this <code>Date</code> object to a <code>String</code>     * of the form:     * <blockquote><pre>     * dow mon dd hh:mm:ss zzz yyyy</pre></blockquote>     * where:<ul>     * <li><tt>dow</tt> is the day of the week (<tt>Sun, Mon, Tue, Wed,     *     Thu, Fri, Sat</tt>).     * <li><tt>mon</tt> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun,     *     Jul, Aug, Sep, Oct, Nov, Dec</tt>).     * <li><tt>dd</tt> is the day of the month (<tt>01</tt> through     *     <tt>31</tt>), as two decimal digits.     * <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through     *     <tt>23</tt>), as two decimal digits.     * <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through     *     <tt>59</tt>), as two decimal digits.     * <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through     *     <tt>61</tt>, as two decimal digits.     * <li><tt>zzz</tt> is the time zone (and may reflect daylight saving     *     time). Standard time zone abbreviations include those     *     recognized by the method <tt>parse</tt>. If time zone     *     information is not available, then <tt>zzz</tt> is empty -     *     that is, it consists of no characters at all.     * <li><tt>yyyy</tt> is the year, as four decimal digits.     * </ul>     *     * @return  a string representation of this date.     * @see     java.util.Date#toLocaleString()     * @see     java.util.Date#toGMTString()     */    public String toString() {        // "EEE MMM dd HH:mm:ss zzz yyyy";        BaseCalendar.Date date = normalize();        StringBuilder sb = new StringBuilder(28);        int index = date.getDayOfWeek();        if (index == BaseCalendar.SUNDAY) {            index = 8;        }        convertToAbbr(sb, wtb[index]).append(‘ ‘);                        // EEE        convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(‘ ‘);  // MMM        CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 2).append(‘ ‘); // dd        CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(‘:‘);   // HH        CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(‘:‘); // mm        CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(‘ ‘); // ss        TimeZone zi = date.getZone();        if (zi != null) {            sb.append(zi.getDisplayName(date.isDaylightTime(), TimeZone.SHORT, Locale.US)); // zzz        } else {            sb.append("GMT");        }        sb.append(‘ ‘).append(date.getYear());  // yyyy        return sb.toString();    }

 

 

sql.date toString方法的原始碼

    /**     * Formats a date in the date escape format yyyy-mm-dd.     * <P>     * @return a String in yyyy-mm-dd format     */    @SuppressWarnings("deprecation")    public String toString () {        int year = super.getYear() + 1900;        int month = super.getMonth() + 1;        int day = super.getDate();        char buf[] = "2000-00-00".toCharArray();        buf[0] = Character.forDigit(year/1000,10);        buf[1] = Character.forDigit((year/100)%10,10);        buf[2] = Character.forDigit((year/10)%10,10);        buf[3] = Character.forDigit(year%10,10);        buf[5] = Character.forDigit(month/10,10);        buf[6] = Character.forDigit(month%10,10);        buf[8] = Character.forDigit(day/10,10);        buf[9] = Character.forDigit(day%10,10);        return new String(buf);    }

 

 

java優秀,值得學習。
學習資源:原始碼 + 清淨的心地。

jdbc-mysql基礎 util.date 和 sql.date 的toString方法是不同的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.