how to store a time value in SQLite database in Android?
I want to store a timevalue in an SQLite database in Android. My time value is in EditText, and when I click the save button I would like the time value to be stored in the database. And als开发者_运维知识库o I want to review the already-stored value in the database.
SQLite doesn't have a specific datatype for storing times, and leaves it up to you whether you want to store them as text, integers, or floating-point values, so you can establish whatever convention works best for you.
For your application where you want the time to be editable by the user I'd suggest looking into the DatePicker and TimePicker widgets, so that you don't have to worry about parsing and formatting the time as text, and then the Java Calendar class for converting the data from those into a simple value that you can put in the database (I'd suggest using the getTimeInMillis() method to convert it into a integer).
Sqlite + timestamp = Date and time functions
Sqlite + timestamp + android = Timestamp Class
Other options
- create a column for each piece of info you wish to store (day, hour, min, second, etc)
- convert time into long and store that instead. Use java.sql.Time
精彩评论