在SQLite中保存datetime类型的最佳方法是什么? [英] What is the best way to save datetime type in SQLite?
问题描述
我正在创建Android应用程序,需要保存创建记录的日期/时间。最好的方法是什么?我将需要比较。例如,在我的应用程序中,我将显示所有记录在日期A到B之间创建。
I’m creating Android apps and need to save date/time of the creation record. What is the best way to do that? I will need to compare it later. For instance, in my apps I will show all record are created between date A until date B.
推荐答案
SQlite没有特定的日期时间类型。您可以使用 TEXT
, REAL
或 INTEGER
类型
SQlite does not have a specific datetime type. You can use TEXT
, REAL
or INTEGER
types, whichever suits your needs.
SQLite没有存储类别用于存储日期和/或时间。相反,SQLite的内置日期和时间函数能够将日期和时间存储为TEXT,REAL或INTEGER值:
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为ISO8601字符串(YYYY-MM-DD HH:MM:SS.SSS)。
- REAL作为朱利安日数字,自1414年11月24日中午在格林威治以来的天数。根据可笑的公历。
- INTEGER作为Unix时间,自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内置日期和时间功能可以 在这里找到 。
SQLite built-in Date and Time functions can be found here.
这篇关于在SQLite中保存datetime类型的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!