简体   繁体   English

Oracle SQL查询将Unix时间戳转换为Java日期

[英]Oracle SQL Query to Convert Unix Timestamp to date for Java

we have a Table which contains Last Published date of Pages. 我们有一个表格,其中包含页面的上次发布日期。 but the field type is number and Page's LastPublished date stored as UnixTimeStamp (13 digit number). 但是字段类型是数字,Page的LastPublished日期存储为UnixTimeStamp(13位数字)。 I want to generate report which contains lastday published items (Everyday more than 20pages will get publish). 我想生成包含昨天发布的项目的报告(每天将发布20页以上的页面)。

If the field is date then i can query but its in Number format. 如果字段是日期,那么我可以查询,但其数字格式。 So, kindly please help me to generate report. 因此,请帮助我生成报告。

Sample Table: 样品表:

ID              Approved       Path                PublishedDate
----------------------------------------------------------------
206b50140aSTFL  approved       /LocaleFlags/Small  1502866591000
dc563a2db23RD   approved       /LocaleFlags/Small  1442230611000

Assuming that your timestamp is in milliseconds (since you say the unix timestamp is 13 digits) then divide by 1000 to get the number of seconds since the epoch and you can use NUMTODSINTERVAL to change that to an interval and add it to the epoch TIMESTAMP '1970-01-01 00:00:00' : 假设您的时间戳以毫秒为单位(因为您说unix时间戳是13位数字),然后除以1000以获取自该纪元以来的秒数,您可以使用NUMTODSINTERVAL将其更改为一个间隔并将其添加到纪元TIMESTAMP '1970-01-01 00:00:00'

SELECT TIMESTAMP '1970-01-01 00:00:00' + NUMTODSINTERVAL( PublishedDate / 1000, 'SECOND' )
FROM   your_table

However, if you just want to find yesterday's pages then convert that date to a unix timestamp : 但是,如果您只想查找昨天的页面,则可以将该日期转换为unix时间戳

SELECT *
FROM   your_table
WHERE  PublishedDate BETWEEN ( TRUNC( SYSDATE ) - 1 - DATE '1970-01-01' ) * 24*60*60*1000
                         AND ( TRUNC( SYSDATE ) - DATE '1970-01-01' ) * 24*60*60*1000 - 1

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

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