I am trying to pass a string of the form 12:00
into milliseconds based on the current date but I seem unable to get a good understanding of how the Calendar
and Date
class work to achieve this.
Now I have this code:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Calendar startTime = Calendar.getInstance();
String alarmPref = preferences.getString(PreferenceUtility.getReminderTimes(context), "12:00");
SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
Date date = format.parse(alarmPref);
startTime.setTime(date);
This unfortunaltely gives me when logged like this:
Log.d(TAG, "Time to start:" + futureTime);
Log.d(TAG, "Date: " + date);
Gives the following results:
07-25 14:45:21.057 8409-8409/com.google.developer.bugmaster D/PreferenceUtility:Time PreferenceUtility: 21:20
07-25 14:45:21.057 8409-8409/com.google.developer.bugmaster D/QuizJobScheduler: Time to start:126000
Date: Thu Jan 01 12:00:00 GMT+01:00 1970
As seen the required string is 21:20
( as expected ) but Time to start
remains at the value 126000
and hence I keep getting the date to be Date: Thu Jan 01 12:00:00 GMT+01:00 1970
, which of course is a reference to the epoch
date and time.
How can I get a reference date and time that refers to the time of 21:20
and for the current date the app is running. Forgive me for my ignorance as I have tried so many literature with no success most likely I am unable to understand them.