javascript - MomentJS returns obscure date for 1st of month -


i'm having small problem momentjs returning nonsense date. attempting set date first of given month , year. have tried following:-

var _year = 2015; var _month = 10; var _datestring = _year.tostring() + '-' + _month.tostring() + '-1'; var _date = moment(_datestring, 'yyyy-mm-d'); console.log('_date', _date.format('dddd, mmmm yyyy')); 

this gives thursday, 4th october 2015 _date. doesn't exist. tried using .set() , .date(), both give same result:-

var _date = moment(_datestring, 'yyyy-mm-d').set('date', 1); > thursday, 4th october 2015  var _date = moment(_datestring, 'yyyy-mm-d').date(1); > thursday, 4th october 2015 

so, can't see i'm doing wrong now, can offer suggestions or help?

many thanks.

your code correct except should use capital d not small d in do:

console.log('_date', _date.format('dddd, mmmm yyyy')); 

difference between do , do is:

  • do index of day in week, example if check calender find 1st october thursday 4th day of week index start 0 , if changed 2 october friday give 5th , same 3 oct => 6th , new week start sunday 4 oct => 0th , start on again.

  • do index of day in month , expected result be, 1th oct 1th, 2nd oct => 2nd , on.

check docs here more info


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -