0

I want to compare the system time with manually given time, this program is not satisfying the condition. How can i do this in 24hrs format.

    Calendar calendar = new GregorianCalendar();  
    String am_pm;  
    int hour = calendar.get(Calendar.HOUR);  
    int minute = calendar.get(Calendar.MINUTE);  
    int second = calendar.get(Calendar.SECOND);  
    if(calendar.get(Calendar.AM_PM) == 0)  
      am_pm = "AM";  
    else  
      am_pm = "PM";    
    String time = hour + ":" + minute + ":" + second + " " + am_pm ;  
    String time1 =  12 + ":" + 40 + ":" + 00 + " " + "PM";  
    if(time==time1)    
    {     
        display(time);  
    }  
    else   
    {  
        display(time);  
    }

I have to do it in android Application. So pls help me.

3 Answers 3

5

This gives the hour (0-23):

int hour = calendar.get(Calendar.HOUR_OF_DAY);
Sign up to request clarification or add additional context in comments.

Comments

0

in Java, you compare strings using string1.equals(string2), not using ==

Comments

0

Strings and other objects should be compared with .equals() method, not == opertor

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.