GetDay () code showing wrong day Javascript
This is my first time (novice yep JS), using the function new Date()
and getDay()
in Javascript. The current date is given correctly, but it gives me the day on Friday, even thought it shows the day on Thursday if I get the current date. I was doing a check of previous questions here, but couldn't see what it really explained. It gives the same result in both Chrome and Firefox. I have also verified that my computer is set to the correct time zone, GMT GMT.
code:
var currentDate = new Date();
console.log(currentDate);
var weekday = ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'];
var day = weekday[currentDate.getDay()];
console.log(day);
Displaying time and day in the console:
"Thu May 11, 2017 22:25:15 GMT + 0100 (BST) Fri"
source to share
Change the array to ['Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat']
.
(Sunday is the first day of the week if Javascript has a word in it;)
var currentDate = new Date();
var weekday = ['Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat'];
var day = weekday[currentDate.getDay()];
console.log(day);
source to share