What is the easiest way to get the current day of the week in Android?

前端 未结 11 1560
南方客
南方客 2020-11-27 02:44

What would be the easiest way to get the current day of the week in Android?

11条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 03:04

    Using both method you find easy if you wont last seven days you use (currentdaynumber+7-1)%7,(currentdaynumber+7-2)%7.....upto 6

    public static String getDayName(int day){
        switch(day){
            case 0:
                return "Sunday";
            case 1:
                return "Monday";
            case 2:
                return "Tuesday";
            case 3:
                return "Wednesday";
            case 4:
                return "Thursday";
            case 5:
                return  "Friday";
            case 6:
                return "Saturday";
        }
    
        return "Worng Day";
    }
    public static String getCurrentDay(){
        SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE", Locale.US);
        Calendar calendar = Calendar.getInstance();
        return dayFormat.format(calendar.getTime());
    
    }
    

提交回复
热议问题