Pergunta

I have the time in milliseconds and I set it to Calendar object for a particular time. This initial time is just supposed to be an estimate of the time, but the actual time is based upon the time of week in milliseconds since Sunday at midnight.

So I need to somehow set the time of week for the Calendar object but I'm having a hard time figuring out how to do this.

Is there a slick way to do this? Am I using the best Java object. I haven't done Java in a long time so it is pretty new to me.

Here's an example : There are 2 things that happen. 1) GM Time in ms for the apoximate time. 01/03/2001 01:00:00 Tuesday. Then I get event 2) GMT Time in milliseconds since Sunday at Midnight (01/01/2001) ) 0:00:00. Lets just say it has been 20000 ms since that date. So now I need to know how to set the actual date /time since midnight, so I can see what that actual time is

Foi útil?

Solução

Try this:

Calendar nowCal = (however you get/set the time you care about, as a Calendar)
long now = nowCal.getTimeInMillis();
long millis_today = now % 86400;
long millis_in_days = (nowCal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY) * 86400L;
long time_since_midnight_sunday = millis_in_days + millis_today;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top