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

146
Views
date.toLocaleTimeString no es una función

Estoy tratando de imprimir la fecha de script.js proveniente de mongodb pero recibo el siguiente error

TypeError no detectado: date.toLocaleTimeString no es una función

 function db_old_msgs(old_msg) { $('.chat-messages').append('<span class="msg"><b>' + old_msg.nick + ': </b>' + old_msg.msg +" "+FormatTime(old_msg.created) + "</span><br/>"); } function FormatTime(time, prefix = "") { var date = Date.parse(time); return ((typeof time != "undefined") ? prefix + date.toLocaleTimeString() : ""); }

Intenté lo anterior sin la función FormatTime como "+ old_msg.created.toLocaleTimeString() +" pero obtengo el mismo error.

El formato de hora que se recibe de db es 2021-12-16T13:22:01.600+00:00.

Las fechas se muestran correctamente y provienen de server.js

 socket.broadcast.emit('msg', {from: users[socket.id],message: message, time:newMsg.created.toLocaleTimeString()})

Muchas gracias

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

0

La fecha venía como una cadena del servidor, así que tuve que convertirla a la fecha y luego pasar la función a LocaleTimeString()

 function db_old_msgs(old_msg) { var dbtime=new Date(old_msg.created); var formattedDate = dbtime.toLocaleTimeString(); $('.chat-messages').append('<span class="msg"><b>' + old_msg.nick + ': </b>' + old_msg.msg +" "+formattedDate + "</span><br/>"); }
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!