So, I have been trying this for a long time. I need to save the date and time as a String (DD-MM-YYYY & HH:mm)
in a SQLite
database.
Now I have to set up my AlarmManager
to show notifications, but AlarmManager takes the time and date in milliseconds.
How can I convert these into milliseconds?
What is the right way to store Date and Time in a SQLite DB
?
You can use SimpleDateFormat to do this:
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm");
String time = "12-01-2014 10:23";
long millis = format.parse(time).getTime();
This should work. I have something like this too, and I set an extra column where I save the milliseconds from this date inside the database, so I can get it directly.