Is there a date format to display the day of the week in java?

后端 未结 6 1529
执笔经年
执笔经年 2020-12-02 07:40

I know of date formats such as
\"yyyy-mm-dd\" -which displays date in format 2011-02-26
\"yyyy-MMM-dd\"-which displays date

6条回答
  •  粉色の甜心
    2020-12-02 08:15

    I know the question is about getting the day of week as string (e.g. the short name), but for anybody who is looking for the numeric day of week (as I was), you can use the new "u" format string, supported since Java 7. For example:

    new SimpleDateFormat("u").format(new Date());
    

    returns today's day-of-week index, namely: 1 = Monday, 2 = Tuesday, ..., 7 = Sunday.

提交回复
热议问题