receivedDate="25022013";
receivedTime="150526";
receivedTime=receivedTime.trim();
String HH = receivedTime.substring(0, 2);
String MM = receivedTime.substring(2, 4);
String SS = receivedTime.substring(4, 6);
receivedTime="date('"+HH+":"+MM+":"+SS+"',strftime('%H:%M:%S'))";
receivedDate=receivedDate.trim();
String dd = receivedDate.substring(0, 2);
String mm = receivedDate.substring(2, 4);
String yyyy = "20"+receivedDate.substring(4,6);
receivedDate="date('"+yyyy+"-"+mm+"-"+dd+"',strftime('%Y-%m-%d'))";
ContentValues values=new ContentValues();
values.put(DBConstants.TIME,receivedTime);
values.put(DBConstants.DATE, receivedDate);
masterDataDB.insert(DBConstants.MASTER_DATA_TABLE, null, values);
此日期和时间插入到 TEXT 类型字段中。当我在 Sqlite 浏览器上看到存储数据时,它存储如下,
在时间字段-> date('15:20:16',strftime('%H:%M:%S'))
在日期字段-> date('2013-02-14',strftime('%Y-%m-%d'))
是否正确存储?如果我使用日期函数选择日期和时间,它会正确返回日期吗?