Li Wu:
Learn to think more, honouring teachers save Thanksgiving. Leaf See Root 321, rivers with one.
Meekness Conscience Lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and cherish.
Javase:8
Os:windows7 x64
Ide:myeclipse
Code
Package com.jizuiku.jdbc;/** * * * * @author to the most bitter * @version V17.11.08 */public class Utildatetosqldate {public Stati c void Main (string[] args) {java.util.Date udate = new Java.util.Date (); System.out.println (udate);//convert java.sql.Date sdate = new Java.sql.Date (Udate.gettime ()); System.out.println (sdate);}}
Effect
Source code for the ToString method of Util.date
/** * 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& gt;). * <li><tt>mon</tt> is the month (<tt>jan, Feb, Mar, APR, May, June, * Jul, April, Sep, OCT, N OV, dec</tt>). * <li><tt>dd</tt> is the day of the month (<tt>01</tt> through * <tt>31</tt >), as a decimal digits. * <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through * <tt>23</tt& gt;), as the decimal digits. * <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through * <tt>59& lt;/tt>), as a decimal digits. * <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through * <tt> ; 61</tt>, as the 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 isn't available, then <tt>zzz</tt> was empty-* that's, it consis TS of no characters at all. * <li><tt>yyyy</tt> is the year and 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 (); }
Source code for the Sql.date tostring method
/** * 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 is good, worth learning.
Learning Resources: Source code + Pure heart.
The ToString method of the Jdbc-mysql base Util.date and Sql.date is different