SóProvas


ID
118669
Banca
FCC
Órgão
TRT - 20ª REGIÃO (SE)
Ano
2010
Provas
Disciplina
Programação
Assuntos

O método getMonth() pode retornar o seguinte intervalo de valores:

Alternativas
Comentários
  • O primeiro valor é:  0, então vai de 0 a 11.

     

    <script type="text/javascript">

    var d=new Date();
    var month=new Array(12);
    month[0]="January";
    month[1]="February";
    month[2]="March";
    month[3]="April";
    month[4]="May";
    month[5]="June";
    month[6]="July";
    month[7]="August";
    month[8]="September";
    month[9]="October";
    month[10]="November";
    month[11]="December";

    document.write("The current month is " + month[d.getMonth()]);

    </script>
  • VAR D=NEW HOUR()

    VAR HOUR=NEW ARRAY(24);

    HOUR[0]="1HORA"

    ...

    HOUR[23]="24HORAS"

    PARA HORAS!

  • CURIOSIDADE:

     

    QUESTION

    "This caused me a bit of a headache last night and I wanted to understand why the getDate method in the Date object is 1 based (returns values from 1-31) while the getMonth method is 0 based (returns 0-11). I'm wondering why there is this inconsistency in methods for the same object.

    I understand why it's difficult to change the behavior now but are there any reasons this was designed like this in the first place?"

     

    ANSWER

    "So I dropped Brendan Eich a tweet asking him the question (for those who don't know he is the creator of JS) and his response was:

    @magrangs because that is how java.util.Date did it."

     

    SOURCE: http://stackoverflow.com/questions/9687521/javascript-date-method-inconsistency-getdate-vs-getmonth

  • c-

    The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.

    https://www.w3schools.com/jsref/jsref_getmonth.asp