A
A
ABU SADDAM SHISHANI2019-07-02 09:38:52
Java
ABU SADDAM SHISHANI, 2019-07-02 09:38:52

If (In a certain period of time) how to make such a condition?

I have text that needs to change color at a certain time of the day (For example, from 9:00 to 10:20)

Date yourDateObject = new Date();;
        txt = (TextView) findViewById(R.id.textView3);
GregorianCalendar timeToCheck = new GregorianCalendar();
        timeToCheck.setTime(yourDateObject);
        int hour = timeToCheck.get(GregorianCalendar.HOUR_OF_DAY);

        if (hour >= 9 & hour <= 10) {
            txt.setTextColor(Color.GREEN);
    }

Everything works, but HOUR_OF_DAY Understands only Hours (Without minutes), and you need to enter the time with minutes.
There is also something like .MINUTE Tried to make a separate variable
...int min = timeToCheck.get(GregorianCalendar.MINUTE);
if (hour >= 9 & hour <= 10&(min <= 20)) {
            txt.setTextColor(Color.GREEN);
    }

But she does not understand the creature that these are exactly 10 minutes (10:20), as a result, at 9 o'clock the same garbage.
why is it so hard in java to just specify a span of time, how to do it???

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question