I want to get the time of a day in milliseconds, I do not this day to have any specific date, just a time. I made something, thought it worked, but then went debugging and concluded that it doesn't work how I want it to.
I want to use this to check if the current time is between both my specified startTime
and endTime
.
long startTime = settings.getLong("startTime", 0);
long endTime = settings.getLong("endTime", 0);
if ((currentTime.getMillis() >= startTime)
&& (currentTime.getMillis() <= endTime)) {
//Do stuff here
}
How I am setting the time of the propeties startTime
and endTime
:
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.HOUR_OF_DAY, 16);
startTime.set(Calendar.MINUTE, 00);
editor.putLong("startTime",
startTime.getTimeInMillis());
Calendar endTime = Calendar.getInstance();
endTime.set(Calendar.HOUR_OF_DAY, 16);
endTime.set(Calendar.MINUTE, 00);
endTime.add(Calendar.HOUR_OF_DAY, 11);
editor.putLong("endTime",
endTime.getTimeInMillis());
editor.commit();
However this will mean that both startTime
and endTime
will have this a specific date attached to it.
I hope I explained it well, any help is appreciated!