Oracle TIMESTAMP的處理,oracletimestamp

來源:互聯網
上載者:User

Oracle TIMESTAMP的處理,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()));
}

}


輸出結果:1970-01-01 00:00:01


oracle的timestamp顯示格式問題

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
---------------------------------------------------------------------------
2011-05-18 16:46:06
 
oracle中timestamp與date類型的不同

此類型由 java.util.Date 和單獨的毫微秒值組成。只有整數秒才會儲存在 java.util.Date 組件中。小數秒(毫微秒)是獨立存在的。傳遞不是 java.sql.Timestamp 執行個體的對象時,Timestamp.equals(Object) 方法永遠不會返回 true,因為日期的毫微秒組件是未知的。因此,相對於 java.util.Date.equals(Object) 方法而言,Timestamp.equals(Object) 方法是不對稱的。此外,hashcode 方法使用底層 java.util.Date 實現並因此在其計算中不包括毫微秒。

鑒於 Timestamp 類和上述 java.util.Date 類之間的不同,建議代碼一般不要將 Timestamp 值視為 java.util.Date 的執行個體。Timestamp 和 java.util.Date 之間的繼承關係實際上指的是實現繼承,而不是類型繼承。
 

相關文章

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.