sqlite3 database write operation time

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/shunli008/article/details/78778606

In today's project, would like to add a time in sqlite3 database, use the original time () function to get the time, written to the database through a simple process, but compared to the following conversion operations too complex

When you create a table just add sqlite

[CreatedTime] TimeStamp NOT NULL DEFAULT (datetime('now','localtime'))

And automatically get a local time when the writing means adding a single data.

This does not need to be added when you add data (table named time, a total of four: id, CreatedTime, name, data)

insert into time(name,data) values('admin', 'login')"

There is also a time to write is to obtain network

[CreatedTime] TimeStamp NOT NULL DEFAULT CURRENT_TIMESTAMP

And it just looked at the statistics, in fact, is a function of acquisition time by a database datetime ()
The following is a reprint

select datetime ( 'now');
Results: 2006-10-17 12:55:54
SELECT datetime ( '2006-10-17');
Results: 2006-10-17 12:00:00
SELECT datetime ( '2006- 10-17 00:20:00 ',' +1 hour ' ,' -12 minute ');
results: 2006-10-17 01:08:00
SELECT DATE (' 2006-10-17 ',' + 1'd Day ',' +1 year ');
results: 2007-10-18
SELECT datetime (' now ',' Start of year ');
results: 2006-01-01 00:00:00
SELECT datetime (' now ',' start of month ');
results: 2006-10-01 00:00:00
SELECT datetime (' now ',' Start of Day ');
results: 2006-10-17 00:00:00
Although the second parameter plus the 10 hours, but was the third argument zero start of day to the time 00:00:00
subsequent fourth parameter based on the time 00:00:00 on 10 hours into increased of 10:00:00.
select datetime ( 'now', ' +10 hour', 'start of day', '+10 hour');
Results: 2006-10-17 10:00:00
The Greenwich time zone conversion cost areas.
select datetime ( 'now', ' localtime');
Results: 2006-10-17 21:21:47
SELECT datetime ( 'now', '+8 hour');
Results: 2006-10-17 21:24:45

Guess you like

Origin blog.csdn.net/shunli008/article/details/78778606