I haven't found a reasonable explanation for a long time. Fortunately, I found an articleArticle, To answer this question, this is a special favorite for your reference.
Http://www.xueit.com/html/2009-02/21_644_00.html
Recently I used ASP. NET + SQLite database to develop a website.ProgramThe result is a headache in date processing.
Note:An error occurred while executing the current Web request. Check the stack trace information to learn about this error andCodeDetailed information about the cause of the error.
Exception details:System. formatexception: the string is not recognized as a valid datetime.
Solution:
Converts a type when the date is saved to the SQLite database, for example, string _ now = system. datetime. Now. tostring ("S ");
That is to say, adding s to the. tostring () method solves the problem of date reading errors.
Simple code example:
String _ indate = request ["indate"]; // The input date, for example, 2009-2-21
Datetime _ intime = convert. todatetime (_ indate );
// The SQL statement for saving data is as follows:
Insert into table (indate) values ('"+ _ intime. tostring (" S ") +"'); // convert
The following date is saved in the SQLite database:
The strange reason is that the date is 1899-12-30. Rest assured that this is normal. Let's see what I read from the date below? As follows:
See, it is the correct date.
Because ISO 8601 Description: (http://msdn.microsoft.com/zh-cn/library/ms187819.aspx)
A string example is provided:
* 2004-05-23t14: 25: 10
* 2004-05-23t14: 25: 10.487
Therefore, the date saved by SQLite must be converted to ISO 8601 standard string format.
Use date. tostring ("S"); this method is converted to ISO 8601 standard string format.