2015年5月17日 星期日

SQLite 時間

目的:

在SQLite中insert時,default值填入current time。

操作:

CREATE TABLE IF NOT EXISTS `test` (
  `curr_time` TIMESTAMP DEFAULT (datetime('now','localtime')) -- 時間
)

  1. `curr_time` TIMESTAMP DEFAULT (datetime('now','localtime')) :目前手機時間
  2. `curr_time` TIMESTAMP DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')) :目前手機時間
  3. `curr_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP :時間有可能非手機目前的時間

insert時間:

in Android:

            ContentValues contentValues = new ContentValues() ;
            contentValues.put( "curr_time", new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format( new Date() ) ) ;
            success = ( db.update( "test", contentValues, null, null ) > 0 ) ;

沒有留言:

張貼留言