你好,我傳遞一些數據到sqlLite數據庫,我想分別發送當前的日期和時間。我對編程相當陌生,所以任何幫助都很棒。我檢查了其他數據正確存儲。將當前日期和時間分別傳遞到sqlite
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "vas_podatki.db";
public static final String TABLE_NAME = "podatki";
public static final String COL_1 = "ID";
public static final String COL_2 = "JAKOST";
public static final String COL_3 = "DAN";
public static final String COL_4 = "URA";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table "+ TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT, JAKOST INTEGER, DAN CURRENT_DATE , URA CURRENT_TIME)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS"+ TABLE_NAME);
onCreate(db);
}
public boolean insertData(String jakost){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2,jakost);
long reuslt = db.insert(TABLE_NAME,null,contentValues);
if (reuslt == -1)
return false;
else
return true;
}
}
是否有特定的原因兒子你需要分開存放他們嗎?如果您只存儲了UTC時間戳,那麼您可以根據需要在代碼中計算出日期和時間。 – Jahnold