about TalkSQLiteThe date type data is accessed online quite a few, but it is found to be so thin. More is to useDate, do not do date data statistical analysis, the access requirements of the relatively small direct conversionLong, i.e.datetime.gettime ()storage. It needs to be displayed on the interface.Longthe date data of the model intoDateorDateTimetype. But if you want to do statistical analysis of the data so that every record to traverse the conversion will be particularly troublesome, the amount of data is large, time consumption is very large.
We know that date type data is in yyyy-mm-dd form in the database , and time is hh:mm form of storage. The DateTime type is stored in yyyy-mm-dd HH:mm:ss.fff, year,month, day, time, minute, second, and millisecond. How do you store data for DateTime types? I believe it's a problem that bothers beginners.
String timestr = "2015-3-1 16:20"; SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Format.settimezone (Timezone.gettimezone ("gmt+08:00"));//Beijing, China Time, East eight zone date dateTime = null; try { dateTime = (Date) format.parse (TIMESTR), } catch (ParseException e) { e.printstacktrace (); }
Java.sql.Date is the data type that is set to match SQL Date . The "normalized" java.sql.Date contains only month and day information, because if the information in the denormalized part of the database exists, such as milliseconds or seconds, it will rob Zero.
To save The exact value of the java.util.Date,
We need to use java.sql.Timestamp .
Timestamp Timestamp = new Timestamp (Datetime.gettime ());
This allows you to Insert a DateTime type of data directly into SQLite with timestamp .
What about that? The key issue should appear in the cursor without a method that specifically takes date data.
Note that the data in theAndroid Sqlite is stored in a weak type. Taken as a String and converted to a date type.
String str; SimpleDateFormat format; Date date = null; str = cursor.getstring (Cursor.getcolumnindex ("corresponding column name")); format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Date = (date) format.parse (str);
Reprint Please specify the Source:http://blog.csdn.net/lindonglian/article/details/44003549
Access Problems with datetime type data in SQLite for Android