问题
How do I use an SQL statement on an sqllite database to insert the current date in UTC. I found the NOW
function but what format is that in? This will be on mobile devices so everyone will have a different locale, however, I need a standard time format because the device will compare the dates with my server.
Also, is there a way to automatically update a 'modified' field when the data in the row is changed like you can in MySQL?
回答1:
SELECT DATETIME('now')
returns the current UTC datetime. See Date And Time Functions. You can use DATETIME DEFAULT CURRENT_TIMESTAMP with column declaration.
Format 11, the string 'now', is converted into the current date and time as obtained from the xCurrentTime method of the sqlite3_vfs object in use. Universal Coordinated Time (UTC) is used
For the 'modified' field you can use a trigger.
回答2:
You don't specify what you use to develop your application on. I prefer using QDate::toJulianDay
and QDate::fromJulianDay
in Qt to store dates in an SQLite database as an integer if I only need to store the date.
来源:https://stackoverflow.com/questions/4266263/sqlite-and-inserting-the-current-date-in-utc-format