在我的团结游戏中,我得到了系统的日期,并将其发送到Sqlite数据库。但在sqlite数据库中,数据被保存为一个4位数字。
这是我用来约会的密码。
PlayerPrefs.SetString("date_time", System.DateTime.Now.ToString("yyyy-MM-dd"));
CurrentDate = PlayerPrefs.GetString("date_time");
我就是这样把它插入数据库的。
//Add new event with o timer at the start of the game
public void AddEvent(){
using (IDbConnection dbConnection = new SqliteConnection(connectionString)){
dbConnection.Open();
using(IDbCommand dbCmd = dbConnection.CreateCommand()){
string sqlQuery = String.Format("INSERT INTO events(date,timer_count) VALUES({0},0)",System.DateTime.Now.ToString("yyyy-MM-dd"));
dbCmd.CommandText = sqlQuery;
dbCmd.ExecuteScalar();
dbConnection.Close();
}
}
PlayerPrefs.SetString("date_time", System.DateTime.Now.ToString("yyyy-MM-dd"));
Debug.Log(PlayerPrefs.GetString("date_time"));
}
在统一编辑器中,当我打印日期时,它是这样的:
但在Sqlite数据库中,它是这样的:
当日期增加时,数量会减少。
例子: 2018-10-28 => 1982 - 2018-10-29 => 1981
我想将数据存储在sqlite数据库中,格式与统一编辑器中显示的格式相同。(Yyyy Dd)
发布于 2018-10-29 16:27:20
向查询添加占位符,如('{0}')
string sqlQuery = String.Format("INSERT INTO events(date,timer_count) VALUES('{0}',0)", System.DateTime.Now.Date);
注意:使用预先准备好的语句来防止sql注入。
https://stackoverflow.com/questions/53040456
复制相似问题