DATETIME值在SQLite中如何工作? [英] How do DATETIME values work in SQLite?

查看:67
本文介绍了DATETIME值在SQLite中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建Android应用,并且需要保存创建记录的日期/时间。 SQLite文档说,但是, SQLite没有为存储日期和/或时间预留存储类,并且能够将日期和时间存储为TEXT,REAL或INTEGER值。

I’m creating Android apps and need to save date/time of the creation record. The SQLite docs say, however, "SQLite does not have a storage class set aside for storing dates and/or times" and it's "capable of storing dates and times as TEXT, REAL, or INTEGER values".

是否有技术原因要使用一种类型而不是另一种类型?而且,单列能否以行与行的三种格式之一存储日期?

Is there a technical reason to use one type over another? And can a single column store dates in any of the three formats from row to row?

我以后需要比较日期。例如,在我的应用程序中,我将显示在日期A到日期B之间创建的所有记录。我担心没有真正的DATETIME列会导致比较困难。

I will need to compare dates later. For instance, in my apps I will show all records that are created between date A until date B. I am worried that not having a true DATETIME column could make comparisons difficult.

推荐答案

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:


  • 文本为ISO8601字符串( YYYY-MM-DD HH:MM:SS.SSS)。

  • REAL为儒略日数,即自公元前4714年11月24日格林威治中午以来的天数。根据公历。

  • INTEGER as Unix Time,是自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.

这篇关于DATETIME值在SQLite中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆