如何在SQLite中将基于2001的时间戳转换为日期时间? [英] How to convert 2001 based timestamp to datetime in SQLite?
问题描述
ZPUBLICATIONDATETIME
的类型为 TIMESTAMP
。
所以当我这样做时:
SELECT strftime('%d - %m - %Y ', datetime(ZPUBLICATIONDATETIME, 'unixepoch')) FROM ZTNNEWS;
我得到的是 26-05-1984
iOS(核心数据)的日期时间为 2001年1月1日
。获得正确日期转换的最佳方法是什么?
I get 26 - 05 - 1984
instead of 2015. iOS (Core Data) writes datetime on 1 Jan 2001
based. What is the best approach to get the right date conversion?
我应该再加上31年还是 unixepoch替代品
放在那里?
Shall I just add 31 years to it or is there an alternative to unixepoch
to put in there?
基本上,我想做的是获取过去两天的记录:
Essentially what I am trying to do is to get the records from past two days:
select *
from ZTNNEWS
where DATETIME(ZPUBLICATIONDATETIME) > DATETIME('now', '-2 day')
但是因为 ZPUBLICATIONDATETIME
的类型为 TIMESTAMP
,而不是Datetime,它不会输出任何内容。
But because ZPUBLICATIONDATETIME
is of type TIMESTAMP
rather than Datetime, it doesn't output anything.
有什么建议吗?
推荐答案
遇到了同样的问题。将日期值添加到 2001年1月1日
的秒数似乎可以完成以下工作:
Just had the same problem. Adding the date value to the seconds of 1 Jan 2001
seems to do the job:
SELECT * FROM ztnnews WHERE DATETIME(zpublicationtime + 978307200) > DATETIME('now', '-2 day');
我用红宝石获得了 2001年1月1日的秒数
:
$ irb
2.2.3 :001 > require "time"
=> true
2.2.3 :002 > Time.parse( "2001-01-01T00:00:00Z").to_i
=> 978307200
这篇关于如何在SQLite中将基于2001的时间戳转换为日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!