How to save time value in SQLite database on Android?

I want to save the timevalue value in a SQLite database on Android. My time value is in EditText, and when I click the save button, I need the time value to be stored in the database. And also I want to view the value already stored in the database.

+7
source share
2 answers

SQLite does not have a specific data type for storing time and leaves it to you whether you want to save it as text, integers, or floating point values, so you can set which convention is best for you.

For your application, where you want the user to edit the time, I would suggest looking at DatePicker and TimePicker , so you don’t have to worry about parsing and formatting the time as text, and then Java Calendar to convert the data from it into a simple value, which you can put in a database (I would suggest using getTimeInMillis () to convert it to an integer).

+6
source

Sqlite + timestamp = Date and Time Functions

Sqlite + timestamp + android = Timestamp

Other options

  • create a column for each piece of information that you want to save (day, hour, min, second, etc.).
  • convert time to long and save it. Use java.sql.Time
+2
source

All Articles