Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display day of the week with Javascript date

Tags:

javascript

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 code below to have it display the day of the week instead such as Friday, Nov 1

I do not need it to display the year.

Any help would be much appreciated as I am stumped.

<script>
var myDate=new Date();
myDate.setDate(myDate.getDate()+7);
var n=myDate.toLocaleDateString();
document.write(n);
</script>
like image 887
user1522879 Avatar asked Oct 25 '13 07:10

user1522879


People also ask

What day of the week is it JavaScript?

Call the getDay() method on the Date object to get the day of the week. The getDay method returns the day of the week for the specific date, represented as an integer between 0 and 6 , where 0 is Sunday and 6 is Saturday.


1 Answers

try this , adding 1 week from current day output you get is :Friday,November 1

<script >
<!--

var m_names = ["January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December"];

var d_names = ["Sunday","Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday"];

var myDate = new Date();
myDate.setDate(myDate.getDate()+7);
var curr_date = myDate.getDate();
var curr_month = myDate.getMonth();
var curr_day  = myDate.getDay();
document.write(d_names[curr_day] + "," + m_names[curr_month] + " " +curr_date);

//-->
</script>
like image 109
Sasi Kathimanda Avatar answered Sep 26 '22 15:09

Sasi Kathimanda