Oracle TIMESTAMP processing, oracletimestamp

Source: Internet
Author: User

Oracle TIMESTAMP processing, oracletimestamp
Public class Test {
Private static final SimpleDateFormat FORMAT = new SimpleDateFormat ("yyyy-MM-dd HH: mm: dd ");

Public static void main (String [] args) throws SQLException {
Oracle. SQL. TIMESTAMP temp = new oracle. SQL. TIMESTAMP ();

System. out. println (convertOrclTimestemp2String (temp, null ));
}

Public static String convertOrclTimestemp2String (oracle. SQL. TIMESTAMP temp, String pattern) throws SQLException {
Java. SQL. Timestamp tt = (java. SQL. Timestamp) temp. toJdbc ();
If (StringUtils. isNotBlank (pattern )){
FORMAT. applyPattern (pattern );
}
Return FORMAT. format (new Date (tt. getTime ()));
}

}


Output result: 00:00:01


The timestamp display format of oracle

Alter session set nls_timestamp_format = 'yyyy-mm-dd hh24: mi: ss ';
SQL> create table wcy_t1 (f1 timestamp );

Table created.

SQL> insert into wcy_t1 values (systimestamp );

1 row created.

SQL> commit;

Commit complete.
SQL> select * from wcy_t1;

F1
---------------------------------------------------------------------------
16:46:06

Timestamp and date types in oracle

This type consists of java. util. Date and a separate millisecond value. Only integer seconds are stored in the java. util. Date component. Fractional seconds (in milliseconds) exist independently. The Timestamp. equals (Object) method never returns true when the Object is passed as an Object that is not a java. SQL. Timestamp instance, because the date millisecond component is unknown. Therefore, compared with the java. util. Date. equals (Object) method, the Timestamp. equals (Object) method is asymmetric. In addition, the hashcode method uses the underlying java. util. Date implementation and therefore does not include in its computing.

Considering the difference between the Timestamp class and the preceding java. util. Date class, we recommend that you do not regard the Timestamp value as an instance of java. util. Date. The inheritance relationship between Timestamp and java. util. Date actually refers to implementation inheritance, not type inheritance.

Contact Us

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.

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.