简体   繁体   English

如何在 iPhone 的 sqlite 中绑定当前日期

[英]How to bind the current date in sqlite for iphone

Does anyone have an idea how to insert current date or bind the current date in sqlite for iphone app?有谁知道如何在 iPhone 应用程序的 sqlite 中插入当前日期或绑定当前日期?

I have used this, to store a String:我用它来存储一个字符串:

sqlite3_bind_text( compiledStatement, 3, [Gjourney UTF8String], -1, SQLITE_TRANSIENT);

Is there any way to store the current date?有没有办法存储当前日期? In my datebase I make the Table hello in which i have the column startdate with a DATETIME dataType.在我的数据库中,我将表格设为hello ,其中我的列startdate具有DATETIME数据类型。

Thanks谢谢

I think try using like this it may help you.我认为尝试像这样使用它可能会对您有所帮助。

dateExpires = [NSDate dateWithTimeIntervalSinceNow: sqlite3_column_double(compiledStatement, 3)];

Cheers.....干杯.....

SQLite understands date/time values entered in the following formats. SQLite 理解以下列格式输入的日期/时间值。 If the format is invalid, SQLite will not give an error, but the function call will return null.如果格式无效,SQLite 不会报错,但是 function 调用会返回 null。

  1. YYYY-MM-DD YYYY-MM-DD
  2. YYYY-MM-DD HH:MM YYYY-MM-DD HH:MM
  3. YYYY-MM-DD HH:MM:SS YYYY-MM-DD HH:MM:SS
  4. YYYY-MM-DD HH:MM:SS.SSS YYYY-MM-DD HH:MM:SS.SSS
  5. YYYY-MM-DDTHH:MM YYYY-MM-DDTHH:MM
  6. YYYY-MM-DDTHH:MM:SS YYYY-MM-DDTHH:MM:SS
  7. YYYY-MM-DDTHH:MM:SS.SSS YYYY-MM-DDTHH:MM:SS.SSS
  8. HH:MM高:MM
  9. HH:MM:SS HH:MM:SS
  10. HH:MM:SS.SSS HH:MM:SS.SSS
  11. now现在
  12. DDDD.DDDD (julian day as floating-point number) DDDD.DDDD(作为浮点数的儒略日)

So code as follows,所以代码如下,

NSDate *today=[NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
NSString *dateString=[dateFormat stringFromDate:today];
[dateFormat release];

Just insert this dateString value, SQLite will recognize it as a date.只需插入此 dateString 值,SQLite 就会将其识别为日期。

NSString *date = [NSDate date];

it returns currunt date.它返回当前日期。 save this date string to SQlite;将此日期字符串保存到 SQlite;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM