Show day of the week with Javascript date

I use the code below to display the date of 7 days in the future. However, this javascript code formats the date in mm / dd / yyyy.

I would like to modify the javascript code below so that it displays the day of the week, not Friday, November 1

I do not need to display the year.

Any help would be greatly appreciated as I am at an impasse.

<script>
var myDate=new Date();
myDate.setDate(myDate.getDate()+7);
var n=myDate.toLocaleDateString();
document.write(n);
</script>
+4
source share
3 answers

try this by adding 1 week from the current day off that you get: 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>
+2
source

Date has a method getDay()that returns the day number, starting from Sunday 0 and continuing with Monday = 1, Tuesday = 2, etc.

, . JavaScript .

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

Use the SimpleDateFormat class, for more help visit http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d hh:mm:ss");
System.out.println(dateFormat.format(new Date()));

result Fri, Oct 25 01:12:16

-1
source

All Articles