Sqlite在存储时间方面与其他数据库不同:
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
**TEXT** as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
**REAL** as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
**INTEGER** as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
在sqlite数据库中存储日期数据的最佳方法是什么?。 TEXT,REAL还是INTEGER?
我对“使用TEXT消耗太空空间感兴趣,使用INTEGER很好但是你在2038年会遇到大问题”这个问题感兴趣
答案 0 :(得分:3)
如果您担心总空间并且不需要在1970年之前的任何毫秒或日期,那么请选择INTEGER。
答案 1 :(得分:1)
这是对的吗?
Format Resolution Min Year Max Year Bytes/Date Text Milliseconds 0 AD 9999 AD 23 or 46 Real Milliseconds? 4713 BC ???? 8 Integer Seconds 1970 AD ???? 8
答案 2 :(得分:0)
如果您不需要几分之一秒,最简单的方法是纪元(1970-01-01 00:00之前或之后的整数秒),精确到-4714-11-24直到5352-11-01 10:52:47
对于人类可读日期的计算,有函数strftime