2012-01-18 118 views
0

在我的应用程序中,我需要在sqlite数据库中保存时间。将日期/时间存储到sqlite数据库

  • 用于插入我写这样的代码:

    时间= [NSDate的日期:sqlite3_column_double(selectAllStmt,1)];

  • 它显示一个警告 “类方法日期没有找到

  • 如果我使用它并不显示一个警告:

时间= [NSDate的dateWithtimeintervelsincenow:sqlite3_column_double(selectAllStmt, 1)];

但是我不需要来存储时间间隔,我只需要存储日期。我该怎么办?

+1

[NSDate的dateWithString:]也许? – 2012-01-18 11:44:31

回答

1

首先从时间值转换您的SQLite数据库列为varchar和传递日期字符串,如查询 -

NSString *strDate = [[[NSString stringWithFormat:@"%@",curDate] componentsSeparatedByString:@" "] objectAtIndex:0]; 

希望这个作品:)

+0

它是NSSTRING,但数据库中的列有DATETIME数据类型 – 2012-01-18 11:58:55

+0

您是否可以将列数据类型更改为VARchar?可以吗? – iphonedev23 2012-01-18 12:01:19

+0

不,它必须是日期时间.. 我这样想,但我的上司不会接受。 – 2012-01-18 12:03:13

相关问题