在iPhone应用程序中将日期持久化到SQLite3 [英] Persisting Dates to SQLite3 in an iPhone Application

查看:112
本文介绍了在iPhone应用程序中将日期持久化到SQLite3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,它将数据保存到SQLite3数据库。



对于每一行我坚持我想包括一个'创建日期'和'上次修改日期'



我的问题是什么是建议的方法将此信息存储在表中?



属性在我的应用程序中表示为NSDate,但我不确定如何在我的表中表示此信息。



似乎SQLite3提供了一个DATETIME类型,但是没有本地的如何解析这些信息的理解。



任何帮助将非常感激。

提前感谢。

解决方案

我通常使用双精灵, / p>

  sqlite3_bind_double(statement,index,[dateObject timeIntervalSince1970]); 

其中dateObject是NSDate *。然后,当从DB中获取数据时,使用

  [NSDate dateWithTimeIntervalSince1970:doubleValueFromDatabase]; 


I am developing an iPhone application that persists data to a SQLite3 database.

For each row I persist I wish to include a 'created date' and a 'last modified date'

My question is what is the recommend approach for storing this information in a table?

The properties are represented as NSDate in my application but I am unsure how to represent this information in my table.

It appears that SQLite3 provides a DATETIME type but does not have a native understanding of how to parse this information.

Any help would be much appreciated.

Thanks in advance.

解决方案

I typically use a double, something like:

sqlite3_bind_double(statement, index, [dateObject timeIntervalSince1970]);

where dateObject is an NSDate*. Then, when getting the data out of the DB, use

[NSDate dateWithTimeIntervalSince1970:doubleValueFromDatabase];

这篇关于在iPhone应用程序中将日期持久化到SQLite3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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