mysql的tostring_jdbc-mysql基础 util.date 和 sql.date 的toString方法是不同的

礼悟:

好好学习多思考,尊师重道存感恩。叶见寻根三二一,江河湖海同一体。

虚怀若谷良心主,愿行无悔给最苦。读书锻炼强身心,诚劝且行且珍惜。

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);

}

}

效果

df22b0f25b6a97468d305cd99ce3a042.png

util.date的toString方法的源代码

/**

* Converts this Date object to a String

* of the form:

*

 
  

* dow mon dd hh:mm:ss zzz yyyy

* where:

*

dow is the day of the week ( Sun, Mon, Tue, Wed,

* Thu, Fri, Sat).

*

mon is the month ( Jan, Feb, Mar, Apr, May, Jun,

* Jul, Aug, Sep, Oct, Nov, Dec).

*

dd is the day of the month ( 01 through

* 31), as two decimal digits.

*

hh is the hour of the day ( 00 through

* 23), as two decimal digits.

*

mm is the minute within the hour ( 00 through

* 59), as two decimal digits.

*

ss is the second within the minute ( 00 through

* 61, as two decimal digits.

*

zzz is the time zone (and may reflect daylight saving

* time). Standard time zone abbreviations include those

* recognized by the method parse. If time zone

* information is not available, then zzz is empty -

* that is, it consists of no characters at all.

*

yyyy is the year, as four decimal digits.

*

*

* @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.

*

* @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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值