Reprinted Please note: http://www.cnblogs.com/naiking/archive/2011/03/24/1994100.html #
Translation: http://verysimple.com/2008/09/09/working-with-dates-in-flex-air-and-sqlite/
I admit that I am poor at English
Paul Roberts from the air team wrote a description similar to the Date type in sqlite. Will instruct air to automatically process the date
Conversion. The problem I encountered with the Date type is that the Date control dateField is used in the DataGrid. The following article
It is helpful for processing Dates in air and sqlite.
It is difficult to handle the date value in sqllite and air interactions, and there are various unknown warnings.
I am troubled by the fact that, despite the built-in UTC function, sqllite will be properly inserted into columns of the DATETME type.
It seems that everything is normal. However, sqllite does not recognize the format similar to DATE. It is only processed as plain text.
Unless you want to apply some date formatting functions to track the returned results of sqlllite, you will not understand this.
Sqllite is so loose in Data Integrity: you can insert anything to any data type column at will,
No warning is given. Although Air calculates the Value Based on the Date column, you will receive the Invalid Date error or
When an unknown error occurs.
The magic solution is: Julian Date Format, which can be recognized by sqllite and air as Date.
The strange thing is that actionscript does not have the built-in function of converting Julian Dates.
Follow the following guidelines when using Date:
1: If you need a strong Date type in Air, the related Sqlite column must be defined as DATETIME type. What's interesting is that DATETIME
It is not a recognized sqllite column type. It is considered as a Numeric value type.
2: When you insert or update a DATETIME column, you must store it in the Julian format (or null. Sqllite accepts many common date formats.
Do not manually enter the date in the sqlite management tool. It is not in the Julian format. However, Air performs different operations on different formats.
Insert a Julian Date manually using an SQL statement: "% J"
UPDATE my_table SET my_column = STRFTIME ('% J', '2017-01-02 03:04:05 ');
// You must note the Julia format before performing operations.
Select * from USERS_Mood where RecordDate> STRFTIME ('% J', '2017-03-01') and RecordDate <STRFTIME ('% J', '2017-03-31 ') and User_ID = 'naiking'
Insert into USERS_Mood (User_ID, RecordDate, MoodValue, MoodInfo) values ('naiking', STRFTIME ('% J', '2017-03-20 03:04:05'), 30, 'Nothing ')
Use Julian Dates in
Public function lpad (original: Object, length: int, pad: String): String
{
Var padded: String = original = null? "": Original. toString ();
While (padded. length <length) padded = pad + padded;
Return padded;
}
Public function toSqlDate (dateVal: Date): String
{
Return dateVal = null? Null: dateVal. fullYear
+ "-" + Lpad (dateVal. month + 1, 2, '0') // month is zero-based
+ "-" + Lpad (dateVal. date, 2, '0 ')
+ "" + Lpad (dateVal. hours, 2, '0 ')
+ ":" + Lpad (dateVal. minutes, 2, '0 ')
+ ":" + Lpad (dateVal. seconds, 2, '0 ')
;
}
Var myDate: Date = new Date (02,200,); // Jan 8 03:04:05 // You can also directly var myDate = new Date (); try it.
Statement. text = "UPDATE my_table SET my_column = strftime ('% J','" + toSqlDate (myDate) + "')";