Cate Daniel
Cate Daniel

Reputation: 744

Javascript get day methods return incorrect days

So I'm trying to use a javascript date object to deal with automatically rolling over the days. However getting the information seems to be difficult.

date = new Date();
console.log(date.toISOString());
date.setTime(date.getTime() + 600000); // 10 minutes
console.log(date.toISOString());
console.log(date.getDay());
console.log(date.getUTCDay());

This returns

"2014-10-23T22:55:34.962Z"
"2014-10-23T23:05:34.962Z"
4
4

I have no idea why it keeps returning a day that is not even close to what the day actually is. My current solution just takes sections of the toISOString and assigns things bassed off of that, but I do want to know why this is doing this.

Upvotes: 0

Views: 41

Answers (1)

Jonathan Gray
Jonathan Gray

Reputation: 2609

Day returns the day of the week, try date instead.

Upvotes: 3

Related Questions