Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 数据库中的日期更改为当前日期_Android_Sqlite_Date - Fatal编程技术网

Android 数据库中的日期更改为当前日期

Android 数据库中的日期更改为当前日期,android,sqlite,date,Android,Sqlite,Date,我正在使用存档日期保存数据,但插入的日期更改为当前日期 当你保存数据时 Calendar currentDate=Calendar.getInstance(); DatabaseOperations DB = new DatabaseOperations(ctx); DB.putInformation(DB, done_today1 + "\n" + done_today2 + "\n" + done_today3, thankful_for1 + "\n" + thankful_for2 +

我正在使用存档日期保存数据,但插入的日期更改为当前日期

当你保存数据时

Calendar currentDate=Calendar.getInstance();
DatabaseOperations DB = new DatabaseOperations(ctx);
DB.putInformation(DB, done_today1 + "\n" + done_today2 + "\n" + done_today3, thankful_for1 + "\n" + thankful_for2 + "\n" + thankful_for3 + "\n" + thankful_for4 + "\n" + thankful_for5, for_relationship, for_kids, for_business, currentDate.get(Calendar.DATE) + "-" + currentDate.get(Calendar.MONTH) + "-" + currentDate.get(Calendar.YEAR));
将数据插入表中

public void putInformation(DatabaseOperations dop,String happenedToday,String thankfulFor,String forRelationship,String forKids,String forBusiness,String currentDate){
    SQLiteDatabase SQ=dop.getWritableDatabase();
    ContentValues cv=new ContentValues();
    cv.put(TableData.TableInfo.DONE_TODAY, happenedToday);
    cv.put(TableData.TableInfo.THANKFUL_FOR,thankfulFor);
    cv.put(TableData.TableInfo.FOR_RELATIONSHIP,forRelationship);
    cv.put(TableData.TableInfo.FOR_KIDS,forKids);
    cv.put(TableData.TableInfo.FOR_BUSINESS,forBusiness);
    cv.put(TableData.TableInfo.CURRENT_DATE,currentDate);
    SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
    Log.d("Database operations", "One Row Inserted");
当我这样检索日期时

Cursor CR = dop.getInformation(dop);
CR.moveToFirst();
Toast.makeText(DisplayTable.this,""+CR.getString(5),Toast.LENGTH_LONG).show();
我得到的是当前日期,而不是数据归档的日期


有人知道为什么会这样吗?

处理日期和时间的最佳方法是始终使用ISO标准时间戳,即带有T和Z的时间戳。这使得在不同时区内转换实际日期变得容易


另一种方法是使用unix时间戳保存日期和时间,它是一个长整数,可以转换为不同时区的实际日期,因此它将根据您的时区始终反映正确的时间。

在SQL中,
当前日期
是指当前日期的关键字

要访问具有相同名称的列,必须引用列名(双引号用于标识符;单引号用于字符串):


使用不同的列名可能更好。

谢谢,但这并不能真正解决问题,问题是数据库中的日期每天都会更改为当前日期。例如,如果我今天提交数据,日期将是2015年9月28日。明天的日期应该是2015年9月28日,而不是2015年9月29日。为什么会这样?
> CREATE TABLE t(current_date);
> INSERT INTO t VALUES('x');
> SELECT current_date FROM t;
2015-09-28
> SELECT "current_date" FROM t;
x
> SELECT 'current_date' FROM t;
current_date