简体   繁体   中英

How to save Servervalue.TIMESTAMP in sqlite as long?

MainData helper = new MainData(this); //Change the name to your Helper Class name
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_LAST_MESSAGE, messageText);
contentValues.put(KEY_LAST_MESSAGE_TIME, ServerValue.TIMESTAMP);
long returnVariable = db.update(TABLE_USER_DATA, contentValues,"RecieversID = '"+MessageRecieverId+"'", null);

if (returnVariable == -1)
    Log.d("Lol", "HAHANO");
else
    Log.d("Lol","Successsfulllllll");

Tried this and there is a line under servervalue.timestamp to convert it to string and if I convert it into the string it shows something like 'sv.timstamp'.

I wasn't the long value which it gives when I save it in firebase. I want the same kind of value to store it in SQLite instead but having a hard time.

Please try to debug or print the log of

ServerValue.TIMESTAMP

I think it is returning Long value and converting Long to String and then setting it up in contentvalues will help

you can do as below

String timestamp= Long.toString(ServerValue.TIMESTAMP);
contentValues.put(KEY_LAST_MESSAGE_TIME,timestamp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM