简体   繁体   English

oracle SQL 将秒转换为日期/时间

[英]oracle SQL convert seconds into date / time

Using Oracle SQL inside APEX.在 APEX 内使用 Oracle SQL。 I need to display seconds (1661596801) as date / time (dd/mm/yyyy - HH24:MI:SS).我需要将秒 (1661596801) 显示为日期/时间 (dd/mm/yyyy - HH24:MI:SS)。

The Seconds valve was create in MySQL - $startTimeinSeconds = time();秒阀是在 MySQL - $startTimeinSeconds = time() 中创建的; - this is successful - 这是成功的

To display the date / time in Oracle SQL I have been using the follow which gives no result:要在 Oracle SQL 中显示日期/时间,我一直在使用以下没有结果:

select TO_DATE("1661596801", "DD/MM/YYYY HH24:MI:SS") from dual; select TO_DATE("1661596801", "DD/MM/YYYY HH24:MI:SS") 从双;

What do wrong?做错了什么?

Thanks, Pete谢谢,皮特

That value looks like number of seconds elapsed since 1st of January 1970 (ie Unix epoch time).该值看起来像自 1970 年 1 月 1 日以来经过的秒数(即 Unix 纪元时间)。 If so, then you could try with this:如果是这样,那么你可以试试这个:

(first, setting session date/time format, just to know what is what . You don't have to do that): (首先,设置 session 日期/时间格式,只是为了知道什么是什么。你不必这样做):

SQL> alter session set nls_date_format = 'dd.mm.yyyy hh24:mi:ss';

Session altered.

and then接着

SQL> select date '1970-01-01' + 1661596801 * interval '1' second result
  2  from dual;

RESULT
------------------------------
27.08.2022 10:40:01

SQL>

which is today at 10:40:01 in the morning.也就是今天上午 10:40:01。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM