Objective-C and sqlite's DATETIME type

前端 未结 4 1302
逝去的感伤
逝去的感伤 2020-12-01 06:14

I have a sqlite3 table that I\'m trying to map to an object in objective-C. One attribute of the table is \'completed_at\' which is stored as a DATETIME.

I want to c

4条回答
  •  一个人的身影
    2020-12-01 06:22

    The formatter is important if you are trying to effect the presentation but if you use if for internal storage, you are defining a string which can defeat the DB-engine's ability to use the value for computation, comparison, sorting, etc. Also, if you are going to have different clients inserting the date value into the DB you would have to write conversion functions everywhere. I used the following and it worked as expected (schema's column defined as DATETIME):

    dateExpires = [NSDate dateWithTimeIntervalSinceNow: sqlite3_column_double(queryStmt, 5)];
    

    I inserted into the SQLITE3 db with the Firefox add-on as "4/12/2010" here in Central time zone. Viewing the value of 'dateExpires' in XCode-debugger displayed as:

    2010-04-12 23:19:48 -0500
    

    Sure enough, that is the correct time.

    Also, to insert into the SQLITE DB you will put the value [NSDate date]

提交回复
热议问题