问题
I have date(01-oct-2014), time (00:37:31), GMT difference(-360) now I want to get the time conveted to CST. The solution can be in javascript Or oracle databse.
I have read several articles but could'nt get any where..can some one help me out on this...
回答1:
In Oracle, to convert your local time to time of another timezone, you need to CAST TIMESTAMP WITH TIMEZONE
.
For example, I want to convert 'IST' Indian standard time, i.e. my local timezone to 'CST', i.e. Central :
SQL> WITH T AS
2 ( SELECT to_timestamp('10/01/2014 11','mm/dd/yyyy hh24') ist FROM dual
3 )
4 SELECT ist,
5 CAST(CAST(ist AS TIMESTAMP WITH TIME ZONE) at TIME zone 'CST' AS TIMESTAMP) cst
6 FROM t
7 /
IST CST
----------------------------------- ------------------------------
01-OCT-14 11.00.00.000000000 AM 01-OCT-14 12.30.00.000000 AM
Take care of Daylight saving
. You might have to take care in understanding CST
and CDT
.
回答2:
There are several ways to do this:
SELECT
(TIMESTAMP '2014-10-01 00:37:31') AT TIME ZONE 'CST',
FROM_TZ((TIMESTAMP '2014-10-01 00:37:31'), 'CST'),
CAST((TIMESTAMP '2014-10-01 00:37:31') AT TIME ZONE 'CST' AS TIMESTAMP)
FROM DUAL;
It depends if the result shall include the new time zone or not.
来源:https://stackoverflow.com/questions/26134951/time-zone-conversion-to-cst-based-gmt-offset