android sqlite datetime demo

    @Override
public void onCreate(SQLiteDatabase db) {
String sql="create table user ( username varchar(20) not null , password varchar(60) not null , regtime DATETIME );";
db.execSQL(sql);
}
        DatabaseDemoHelper dbDatabaseDemoHelper = new DatabaseDemoHelper(getApplicationContext());
SQLiteDatabase db = dbDatabaseDemoHelper.getWritableDatabase();
db.execSQL("delete from user", new Object[] {});
ContentValues vls = new ContentValues();
vls.put("username", "zhangsan");
vls.put("password", "123");
vls.put("regtime", new Date().toString());
db.insert("user", null, vls); ContentValues vls2 = new ContentValues();
vls2.put("username", "lisi");
vls2.put("password", "567");
vls2.put("regtime", new Date().toString());
db.insert("user", null, vls2); //new Date().toString() Fri Nov 06 23:58:57 GMT+08:00 2015
//new Date().toLocaleString() 2015年11月7日 上午12:01:42
//new Date().toGMTString() 6 Nov 2015 16:00:02 GMT Cursor cursor = db.rawQuery("select * from user order by regtime desc ", new String[] {});
while (cursor.moveToNext()) {
String userName = cursor.getString(cursor.getColumnIndex("username"));
String password = cursor.getString(cursor.getColumnIndex("password"));
String regtime = cursor.getString(cursor.getColumnIndex("regtime"));
int i = 8;
}
上一篇:Cordova 设置全屏及退出全屏切换


下一篇:e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step (二) 图片验证码的识别