问题
I am using Moment.js for adding dates to an option list I am making, so that I can use those dates to show available appointments, for example, someone can select Friday, February 3rd from the option list and then a list of available times will show up for February 3rd.
What I am having trouble with is I am using an online scheduling api that takes month values that start at 1, for example, January is 01, February is 02, etc. but moment.js months start at 0 and only go up to 11, for example, January is 0, February is 1, etc. I need to be able to convert the values from moment.js into an integer so I can add 1 to each to account for the difference.
The real problem is I tried using parseInt(Month) to get the int value to add one to it, but that didn't work. Here is my code attempting to do just that:
var d = moment(),
Month = d.month();
var GetMonthint = parseInt(Month),
GetMonth = GetMonthint++;
GetAppointmentDates(GetMonth, Year);
GetMonth still only returns 1 for February, is there some special way I can get the int value from the month?
回答1:
The line
GetMonth = GetMonthint++;
is the problem. The ++ operator returns the original value not the incremented value. You should do this:
GetMonth = GetMonthint + 1;
来源:https://stackoverflow.com/questions/42030733/how-to-get-the-integer-value-of-month-from-moment-js