1

I created a table in sqlite database that is something like this:

CREATE TABLE users(
    id INTEGER PRIMARY KEY,
    username TEXT,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

When I insert data in this table, the date field is automatically set.

When I try to retrieve the content of the inserted row.

c.getString(c.getColumnIndex("created_at")));

where c is the Cursor.

The date I retrieve is 1 hour behind the correct date. Consider that I'm in Italy (UTC+1.00)

How can I obtain the correct date?

hcpl
  • 17,382
  • 7
  • 72
  • 73
GVillani82
  • 17,196
  • 30
  • 105
  • 172

2 Answers2

1

CURRENT_TIMESTAMP will record the current time in UTC time zone.

Use e.g. SimpleDateFormat if you want to format your datetime stamps to other timezones.

laalto
  • 150,114
  • 66
  • 286
  • 303
0

Please consider Day Light Saving time.. This may be the problem as DST is there.. That can be the difference of time.

CREATE TABLE whatever(
     ....
     timestamp DATE DEFAULT (datetime('now','localtime')),
     ...
);
Vishal Khakhkhar
  • 2,106
  • 3
  • 29
  • 60