Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
¿Por qué regresa indefinido para el mes? fecha JS
var date = new Date(); var month = date.getMonth(); var arr = [ 'лютого', 'березня', 'квітня', 'травня', 'червня', 'липня', 'серпня', 'вересня', 'жовтня', 'листопада', 'грудня', 'січня', ]; $('.rf_title').text('Данi оновлено ' + date.getDate() + ' ' + arr[month-1] + ' ' + date.getFullYear() +' о ' + (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' + '' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()));

Estoy confundido en cuanto a por qué esto se muestra indefinido. Funcionó bien hasta Año Nuevo. Tan pronto como llegue el 2022, habrá terminado. ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El mes es de índice 0, por lo que eliminar el -1 en el month-1 funcionará (si mueve enero al comienzo de la matriz).

Desde ahora, en enero, usará -1 , lo cual es incorrecto.

El método getMonth() devuelve el mes en la fecha especificada según la hora local, como un valor basado en cero (donde cero indica el primer mes del año).

Forma correcta de hacerlo:

 var date = new Date(); var month = date.getMonth(); var arr = [ 'січня', 'лютого', 'березня', 'квітня', 'травня', 'червня', 'липня', 'серпня', 'вересня', 'жовтня', 'листопада', 'грудня', ]; console.log(arr[month]) $('.rf_title').text('Данi оновлено ' + date.getDate() + ' ' + arr[month] + ' ' + date.getFullYear() +' о ' + (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' + '' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()));
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report

0

El método getMonth() devuelve el mes en la fecha especificada según la hora local, como un valor basado en cero (donde cero indica el primer mes del año). Así que ahora en enero devuelve 0. Y arr[month-1] sería arr[-1] que no está definido.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!