使用to_char(time,'dd-mm-yyyybc','nls_date_language=American') ,才顯示出bc和ad。以下: html
SQL> select time,to_char(time,'dd-mm-yyyybc','nls_date_language=American') AS TRUDATE; TIME TRUEDATE --------------------------------------------------------------------------- 01-JAN-10 12.00.00.000000 AM 01-01-2010bc 01-JAN-10 12.00.00.000000 AM 01-01-2010ad
在PG中:直接查詢便可顯示BC,以下: java
highgo=# select * from testtime; id | time ----+------------------------ 1 | 2010-01-01 00:00:00 2 | 2010-01-01 00:00:00 BC
System.out.println("DataType: "+rs.getMetaData().getColumnTypeName(1)); rs.next(); System.out.println("getString: " + rs.getString(1)); Timestamp time1= rs.getTimestamp(1); System.out.println("getTimestamp: " + time1); rs.next(); System.out.println("getString: " + rs.getString(1)); Timestamp time2= rs.getTimestamp(1); System.out.println("getTimestamp: " + time2); System.out.println("time1Compare2Time2: "+ time1.compareTo(time2));
Oracle的輸出結果: sql
DataType: TIMESTAMP
getString: 2010-01-01 00:00:00.0
getTimestamp: 2010-01-01 00:00:00.0
getString: -2010-01-01 00:00:00.0
getTimestamp: 2011-01-01 00:00:00.0
time1Compare2Time2: 1
分析:該結果說明了java獲得的字符串是帶時間符號的,獲得的時間戳卻不帶符號,可是比較的結果倒是正確的(2010-01-01 要比 2010-01-01 BC更將來),可是獲得的時間戳倒是一個不帶符號的怪異的值,搜索網絡,獲得一個來PG文檔的符合的解釋(雖然相符,但沒法保證確切性,還有待進一步查證):If BC has been specified, negate the year and add one for internal storage. (There is no year zero in the Gregorian calendar, so numerically 1 BC becomes year zero.) 意思是:若是聲明瞭 BC 則對年份取其負數並加一,用於內部保存。由於在格里高利曆法裏沒有零年,因此數字上的 1BC 是公元零年。
(網址:http://www.postgresql.org/docs/9.2/interactive/datetime-input-rules.html) 數據庫
PG的輸出結果: 網絡
DataType: timestamp
getString: 2010-01-02 00:00:00
getTimestamp: 2010-01-02 00:00:00.0
getString: 2010-01-02 00:00:00 BC
getTimestamp: 2010-01-02 00:00:00.0
time1Compare2Time2: 1
分析:這個結果的字符串是標明公元前的,可是獲得的時間戳卻沒有任何的區別,可是對兩個時間戳比較的結果仍然是正確的(即2010-01-01 要比 2010-01-01 BC更將來). oracle
文本time.csv中存儲如下內容,使用copy testtime from 'G:/time.csv' with csv;,結果copy成功,查詢數據無誤。 post
"3","2011-01-02 00:00:00" "4","2011-01-02 00:00:00 BC"