0

I used script to change from TIMESTAMP in Oracle from Json to dd/mm/yy, but the function getMonth of javascript return month fail. In example below, the Month is 3 but it return is 2. Why? Please help.

    var date = "/Date(1520996412000)/";
    var fullDate = new Date(date.match(/\d+/)[0] * 1);
    var twoDigitMonth = fullDate.getMonth() + "";
    console.log(fullDate);
    console.log(twoDigitMonth);

3

2 Answers 2

4

The getMonth() method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year).

2
  • Thanks. This mean we need set twoDigitMonth = twoDigitMonth + 1? Mar 14, 2018 at 6:48
  • If you are wanting your months to be represented as 1-12 as instead of 0-11, then yes you are correct.
    – Joseph M
    Mar 14, 2018 at 6:49
1

getMonth() method's return value:

An integer number, between 0 and 11, representing the month in the given date according to local time. 0 corresponds to January, 1 to February, and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.