jdbc-mysql基础 util.date 和 sql.date 的toString方法是不同的
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jdbc-mysql基础 util.date 和 sql.date 的toString方法是不同的,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3870字,纯文字阅读大概需要6分钟。
内容图文
![jdbc-mysql基础 util.date 和 sql.date 的toString方法是不同的](/upload/InfoBanner/zyjiaocheng/494/de01f22c83034ece90430d3f867fa2e9.jpg)
礼悟:
好好学习多思考,尊师重道存感恩。叶见寻根三二一,江河湖海同一体。
虚怀若谷良心主,愿行无悔给最苦。读书锻炼强身心,诚劝且行且珍惜。
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方法是不同的
标签:new esc time escape rar sprintf .sql stat available
本文系统来源:http://www.cnblogs.com/jizuiku/p/7827341.html
内容总结
以上是互联网集市为您收集整理的jdbc-mysql基础 util.date 和 sql.date 的toString方法是不同的全部内容,希望文章能够帮你解决jdbc-mysql基础 util.date 和 sql.date 的toString方法是不同的所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。