问题
I am new to Oracle and hope someone can clarify this scenario for me.
I have written a very large query that returns a set of dates with it (Oracle 10g).
In SQL Developer, these dates appear in DD-MON-YY format (ex: '12-MAY-12'). The field's data type in SQL Developer shows it is a Date type, and the Simple radio button is checked. When I run this query in SQL Developer, I get a date that looks like this:
11-MAY-12
I use this query in an assembly that is part of a C# web service. Someone on our offshore team where our QE servers are hosted noticed that the field's value is being converted to an IST offset (it's converted to XML using GetXml for the DataSet). The thing is, I didn't even know the offset was there until I inspected the output in a debugger since I can't see it in SQL Developer. It's coming over like this:
2012-05-11T06:09:15+05:30
There's no intrinsic date conversion function used, just the name of the field that pulls out the date.
How can I modify my query so that the offset coming over (we do need to preserve the time portion of the Date) is not taken into consideration when the query is run? I know the question sounds convoluted, but the end result is data being written to another database overseas contains the wrong offset, so it's being converted to dates that are off by 1 day.
Basically I want the time but not the offset.
回答1:
An Oracle DATE
has a day and a time component but no time zone. A TIMESTAMP WITH [LOCAL] TIME ZONE
will have a time zone and will also have sub-second precision.
You can change how the DATE
data is converted into a string for display in a few different ways. First, it to use an explicit TO_CHAR
SELECT to_char( <<your_date_column>>, 'YYYY-MM-DD HH24:MI:SS' )
FROM your_table
Second, you can change the NLS_DATE_FORMAT
of your session so that the session always displays data in a particular format
ALTER SESSION SET nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
SELECT <<your_date_column>>
FROM your_table
Third, in SQL Developer, you can change the string format it uses to display DATE
data. If you go to Tools | Preferences | Database | NLS
, there will be a Date Format
field. If you change that from DD-MON-RR
to YYYY-MM-DD HH24:MI:SS
, you'll get the day and the time displayed by default.
来源:https://stackoverflow.com/questions/10588565/timezone-time-date-formats-with-oracle-and-net