iOS关于SQLite存取时间数据类型的两条常用方法。
2015-04-22 18:09
441 查看
1.把时间通过NSDateFormatter 通过stringFromDate某种格式,然后存字符串。取的时候同样取某个串,通过同一个formatter 的dateFromDate获取NSDate对象。
I typically use a double, something like:
where dateObject is an NSDate*. Then, when getting the data out of the DB, use
[code] NSDateFormatter*dateFormat =[[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString*dateString=[dateFormat stringFromDate:[NSDate date]]; sqlite3_bind_text(saveStmt,1,[dateString UTF8String],-1, SQLITE_TRANSIENT); 2.把时间通过NSDate的timeIntervalSince1970获取double类型存进数据库, 取时间时会通过NSDate timeIntervalSince1970:doubleValue 获取NSDate对象。
I typically use a double, something like:
[code]sqlite3_bind_double(statement, index,[dateObject timeIntervalSince1970]);[/code]
where dateObject is an NSDate*. Then, when getting the data out of the DB, use
[code][NSDate dateWithTimeIntervalSince1970:doubleValueFromDatabase];[/code]
友情链接: http://stackoverflow.com/questions/302664/objective-c-and-sqlites-datetime-type http://stackoverflow.com/questions/251155/persisting-dates-to-sqlite3-in-an-iphone-application http://stackoverflow.com/questions/1711504/how-get-a-datetime-column-in-sqlite-with-objective-c/1711591#1711591[/code]
相关文章推荐
- 关于解决从F1BOOK中读取时间类型的数据的方法
- iOS上常用四种数据存取方法
- ios开发----应用数据存储的常用方法之plist存取方法
- ios开发----应用数据存储的常用方法之plist存取方法
- iOS中常用的四种数据持久化方法简介
- iOS中常用的四种数据持久化方法简介
- 关于iOS去除数组中重复数据的几种方法
- iOS开发 数据存取方法 对象归档
- Android的Sqlite中DateTime类型数据的存取问题
- python和php的基本数据类型的定义赋值及常用方法函数
- iOS CoreData 存取数组字典等数据类型
- iOS中常用的数据类型转换
- [2]姥爷幽默谈Objective-C(getter,setter,init 方法、和类方法以及常用数据类型的介绍)
- iOS中常用的四种数据持久化方法简介
- iOS中常用的四种数据持久化方法简介
- IOS常用数据校验方法,验证手机号,信用卡号,电话号码,邮编,Email等
- MySQL中关于日期、时间的数据类型和函数
- MySQL中关于日期、时间的数据类型和函数
- IOS之持久化数据的常用5种方法
- IOS之持久化数据的常用5种方法