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

141
Views
¿Cómo agregar la fecha y hora actuales en la tabla?

¿Cómo puedo agregar la fecha y hora actual con este formato: 2022-07-17 17:50:20 ?

Ya lo logré con un valor de entrada pero necesito la hora actual.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Puede formatear la fecha ISO mediante funciones de JavaScript de la siguiente manera:

 // Create element: var todayDate = new Date().toISOString(); const dateField = document.createElement("p"); dateField.innerText = new Date().toISOString().split('.')[0].split('T').join(' '); // Append to body: document.body.appendChild(dateField); // Output: 2022-07-17 16:31:22
about 4 years ago · Santiago Gelvez Report

0

Debe usar el objeto Fecha incorporado en Javascript, así:

 let currentdate = new Date(); let datetime = currentdate.getFullYear() + "-" + String((currentdate.getMonth() + 1)).padStart(2,"0") + "-" + String(currentdate.getDate()).padStart(2,"0") + " " + String(currentdate.getHours()).padStart(2,"0") + ":" + String(currentdate.getMinutes()).padStart(2,"0") + ":" + String(currentdate.getSeconds()).padStart(2,"0"); //The `+1` on the getMonth() is used because in Javascript January is 0. console.log(datetime);

Por cierto, le sugiero que convierta todas sus var s en let s ya que ese es el estándar actual. Hay una diferencia muy fina entre ellos (let tiene un alcance de bloque mientras que var tiene un alcance funcional).

about 4 years ago · Santiago Gelvez 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!