Rob
Rob

Reputation: 10248

breeze date (ko.observable) to moment not converting correctly

I have a breeze entity with a date in it, I need to get the year, month, day separately and was going to use momentjs to do it but I'm getting some strange results for something that I would have thought would be quite simple:

var dob = moment(observableDate());
console.log(observableDate() + '  to ->  ' + dob.day() + ' - ' + dob.month() + ' - ' + dob.year());

//ouput
//Thu Dec 18 1975 11:00:00 GMT+1100 (AUS Eastern Summer Time)  to ->   4 - 11 - 1975 

I don't understand where the 4th of Nov is coming from....

The date is stored in Sql Server and the value is '1975-12-18 00:00:00.000'

Thanks in advance.

Upvotes: 0

Views: 130

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

According to the moment.js documentation

day() returns the day of the week, i.e. a number between 0 and 6; (4 == thursday).

month() returns the month of the year but 0 origin. i.e. a number between 0 and 11 - (11 == december)

See: Moment.js docs

Upvotes: 1

Related Questions