How to determine day of week by passing specific date?

前端 未结 25 1427
夕颜
夕颜 2020-11-22 05:12

For Example I have the date: \"23/2/2010\" (23th Feb 2010). I want to pass it to a function which would return the day of week. How can I do this?

I

25条回答
  •  囚心锁ツ
    2020-11-22 05:29

    Calendar class has build-in displayName functionality:

    Calendar.getInstance().getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault()); // Thu   
    
    Calendar.SHORT -> Thu
    Calendar.LONG_FORMAT -> Thursday
    

    Available since Java 1.6. See also Oracle documentation

提交回复
热议问题