使用to_char(time,'dd-mm-yyyybc','nls_date_language=American') ,才显示出bc和ad。如下:
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,如下:
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的输出结果:
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更未来).
文本time.csv中存储以下内容,使用copy testtime from 'G:/time.csv' with csv;,结果copy成功,查询数据无误。
"3","2011-01-02 00:00:00"
"4","2011-01-02 00:00:00 BC"
来源:oschina
链接:https://my.oschina.net/u/1158288/blog/162508