作者:卝軎亟_621 | 来源:互联网 | 2023-02-11 18:40
我目前在我的Android应用程序上的时间排名有问题.我正在使用sqlite
数据库来存储用户完成解决问题的时间.sqlite
稍后我将使用该数据库来显示玩游戏的用户的排名.
例如,玩家以大约1:25 (1分25秒)完成拼图,应用程序将存储1:25
在sqlite数据库中.但我这样做有问题.
我可以将它存储在sqlite
一个string
但我无法使用ORDER
BY
.
我尝试将其存储为int
输出但输出无效int
我试图把它作为一个string
同时去除冒号(:),但在返回"125"数据库.
我的问题是:在数据库上存储特定时间值的最佳方法是什么sqlite
?
我阅读了http://www.sqlite.org/lang_datefunc.html有关时间和日期函数的文档,但它似乎无法应用于自定义时间.它仅适用于现在的日期或当前时间.我需要帮助.我是一个机器人和sqlite业余爱好者.这个项目是我的论文.
任何意见和建议都被接受.提前致谢!
顺便说一句,这是检索我的sqlite上的所有数据的代码.这是一个测试程序,用于测试我的代码/修改代码并查看它们是否正常工作.
try {
String selectQuery = "SELECT * FROM " + DatabaseHelper.TABLE_OUTLET + " WHERE category LIKE '" + cat + "' ORDER BY category ASC";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
// Read columns data
int outlet_id = cursor.getInt(cursor.getColumnIndex("outlet_id"));
String outlet_name = cursor.getString(cursor.getColumnIndex("outlet_name"));
String outlet_type = cursor.getString(cursor.getColumnIndex("outlet_type"));
String category = cursor.getString(cursor.getColumnIndex("category"));
// dara rows
TableRow row = new TableRow(context);
row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
String[] colText = {outlet_name, outlet_type, category};
for (String text : colText) {
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv.setGravity(Gravity.CENTER);
tv.setTextSize(16);
tv.setPadding(5, 5, 5, 5);
tv.setText(text);
row.addView(tv);
}
tableLayout.addView(row);
}
}
db.setTransactionSuccessful();
} catch (SQLiteException e) {
e.printStackTrace();
} finally {
db.endTransaction();
// End the transaction.
db.close();
// Close database
}
}
Shreyash S S..
5
1:25
将此转换为秒.
那是1 * 60 + 25 = 85
.所以商店85
.
每次要存储它都会这样做.你可以在恢复方面做相反的事情.
在例子中,
sec = 85 % 60 = 25
min = 85 / 60 = 1
你会得到 1:25
1> Shreyash S S..:
1:25
将此转换为秒.
那是1 * 60 + 25 = 85
.所以商店85
.
每次要存储它都会这样做.你可以在恢复方面做相反的事情.
在例子中,
sec = 85 % 60 = 25
min = 85 / 60 = 1
你会得到 1:25