Display day of the week with Javascript date

后端 未结 2 848
太阳男子
太阳男子 2020-12-20 22:47

I am using the code below to display a date 7 days in the future. However this javascript code formats the date by mm/dd/yyyy.

I would like to modify the javascript

2条回答
  •  没有蜡笔的小新
    2020-12-20 23:11

    Date has a getDay() method which returns a day number, starting with Sunday on 0 and continuing with Monday=1, Tuesday=2 and so on.

    You can use that to return just the week day. See How to get the day from a particular date using JavaScript and similar questions.

    document.write(["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][myDate.getDay()]);
    

提交回复
热议问题