Blog
Community
Homepage
New essay
Contact
Management
Subscription
Post-42-0 comments-72 differences between java. util. Date and java. SQL. Date and the application of java. util.
Convert a string in the format of "yyyy-mm-dd" to Java. SQL. Date:
Simpledateformat bartdateformat = new simpledateformat ("yyyy-mm-dd "); String datestringtoparse = "2007-7-12 "; Try { Java. util. Date = bartdateformat. parse (datestringtoparse );
(millionSeconds );
Or: java. SQL. Timestamp sTimestamp = new java. SQL. Timestamp (millionSeconds );
Use generic design toSql () method:
First, design an enumeration class Type:
enum Type { DATE, TIME, TIMESTAMP }
It specifies the SQL TIME type to be obtained from the toSql () method: DATE corresponds to
monks made a small summary of the conversion methods of the two, I hope you will give me some advice.Relationship between the twoJava. Lang. Object|+ --- Java. util. Date|+ ---- Java. SQL. DateFrom this figure, we can know that Java. SQL.
Java. SQL. date is used in JDBC, but the problem is that only the date data is stored, not the time data. Time data will be lost:Preparedstatement. setdate (1, new java. SQL. date (date. gettime ()));
Solution: preparedstatement.
This problem is summarized as follows:
Java. SQL. date is a subclass of Java. util. date. A thin package that encapsulates millisecond values allows JDBC to mark millisecond values as SQL date values. To be consistent with the def
Java.
Util. Date And java.
SQL. Date Differences
Root directoryJava.Util. DateIn addition to SQL statementsJava.SQL. DateIt is used for SQL statements. It only contains the date and no time.It has the gettime method th
Label:---restore content starts--- JAVA processing Time-java.sql.Date, java.util.Date and the conversion method of the Date field in the database, and the conversion of the date class and the string under the Util package The date time class used in the
The Set Method of Java. util. date does not seem to have much to do with the struts2 type conversion, but in some cases, java. util. date needs to be converted to be set, especially when struts2 is used.
This is the case. The proj
In spring mvc3, JACKSON mentioned related date problems in serialization of date formats (http://jackyrong.iteye.com/admin/blogs/1089909. Similarly, if the REST format is returned in JAXB, the problem also exists. Let's continue with the example:
1) POJO class:Package com. loiane. model;
Import java. util.
Date class in java. utilWww.linuxaid.com.cn 01-09-20 496 p everywhere--------------------------------------------------------------------------------In JSP, we often need to process date and time information. In this case, you can use java. the Date class in
The time displayed when JSONArray. fromObject is used when the object contains java. util. Date.
During the two days of Project creation, an object needs to be converted into a JSONArray in the action. I am using JSONArray. fromObject. However, data of other String types has been obtained on the page, that is, there is a problem with the
When the number of days lag or forward is within a certain amount of time, the following methods can be used to processpublic static date Getvalidendtime (date Date,int validdaycount) {SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd");String datestr = Sdf.format (date);try {
Java utilities Util functions (Date Processing and http), javautil/*** Returns the day of the year based on the date.* @ Param date* @ Return*/Public static int orderDate (String dateStr ){If (dateStr = null | dateStr. trim (). length () = 0) return 0;Int dateSum = 0;Int yea
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.