Displaying the Time in AM/PM format in android

后端 未结 8 599
醉梦人生
醉梦人生 2020-12-10 13:27

I am getting the time using a time picker and displaying the time in the text view using following code...

private TimePickerDialog.OnTimeSetListener mTimeSe         


        
8条回答
  •  囚心锁ツ
    2020-12-10 13:47

    // Best Result Give Bapu_Darbar:::
    
    Date dt = new Date(); int hours = dt.getHours(); int min = dt.getMinutes(); int am_pm = Calendar.AM_PM;
    
        if(hours>=1 || hours<=3 && am_pm == Calendar.AM){
            spl_text.setText("Welcome \n Good Night,Sweet Dream");
        }else if(hours>=4 || hours<=12 && am_pm == Calendar.AM){
            spl_text.setText("Welcome \n Good Morning,Have A Nice Day");
        }else if(hours>=13 || hours<=17 && am_pm == Calendar.PM){
            spl_text.setText("Welcome \n Good Afternoon");
        }else if(hours>=18 || hours<=20 && am_pm == Calendar.PM){
            spl_text.setText("Welcome \n Good Evening");
        }else if(hours>=21 || hours<=24 && am_pm == Calendar.PM){
            spl_text.setText("Welcome \n Good Night,Sweet Dream");
        }
    

提交回复
热议问题