开发者

how to get and auto enter current date in sqlite db in java?

I want to automatically enter the date time of the data into the database table. I am using the Date field and used timeEntry=DATE('NOW') but when I did a query, the开发者_C百科 output is "DATE('NOW') instead of the time.

Can anyone kindly help me out ? Thanks.


First of all - SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

  • TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
  • REAL as Julian day numbers, the number of days since noon in
    Greenwich on November 24, 4714 B.C. according to the proleptic
    Gregorian calendar.
  • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

SQLite supports five date and time functions as follows:

  1. date(timestring, modifier, modifier, ...)
  2. time(timestring, modifier, modifier, ...)
  3. datetime(timestring, modifier, modifier, ...)
  4. julianday(timestring, modifier, modifier, ...)
  5. strftime(format, timestring, modifier, modifier, ...)

You can replace timestring with 'now' to get the current datetime value.

For more information please see SQLite date and time functions


If you are inputting the value of timeEntry via ContentValues be aware that these values are properly sanitized resulting in timeEntry being assigned a TEXT value & not the result of the function you are passing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜