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

前端 未结 11 1482
南方客
南方客 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:14

    If you do not want to use Calendar class at all you can use this

    String weekday_name = new SimpleDateFormat("EEEE", Locale.ENGLISH).format(System.currentTimeMillis());
    

    i.e., result is,

    "Sunday"
    
    0 讨论(0)
  • 2020-11-27 03:15

    Java 8 datetime API made it so much easier :

    LocalDate.now().getDayOfWeek().name()
    

    Will return you the name of the day as String

    Output : THURSDAY

    0 讨论(0)
  • 2020-11-27 03:17
    Calendar.getInstance().get(Calendar.DAY_OF_WEEK)
    

    or

    new GregorianCalendar().get(Calendar.DAY_OF_WEEK);
    

    Just the same as in Java, nothing particular to Android.

    0 讨论(0)
  • 2020-11-27 03:17

    Here is my simple approach to get Current day

    public String getCurrentDay(){
    
        String daysArray[] = {"Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday", "Saturday"};
    
        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DAY_OF_WEEK);
    
        return daysArray[day];
    
    }
    
    0 讨论(0)
  • 2020-11-27 03:21

    As DAY_OF_WEEK in GregorianCalender class is a static field you can access it directly as foolows

    int dayOfWeek = GregorianCalender.DAY_OF_WEEK;

    0 讨论(0)
提交回复
热议问题