“Fecha y hora JavaScript” Código de respuesta

Mostrar hora y fecha en JavaScript

<!DOCTYPE html>
<html>
<body>

<button type="button"
onclick="document.getElementById('display').innerHTML = Date()">
Click me to display Date and Time.</button>

<p id="display"></p>

</body>
</html>
Rick Astley

Hora de fecha de JavaScript

//Date, Time, Timestamp
var today = new Date();
var DD = String(today.getDate()).padStart(2, '0');
var MM = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var YYYY = today.getFullYear();
var hh = today.getHours();
var mm = today.getMinutes();
var ss = today.getSeconds();
today = YYYY + MM + DD + hh + mm + ss;
console.log('Date-Time: ', today);
Jedi

fecha de fecha js

//Do you need the current time ? ⌚
let date = new Date();
let time = ((date.getHours().toString()).length>1? date.getHours() : "0"+date.getHours()) +":"+ ((date.getMinutes().toString()).length>1? date.getMinutes() : "0"+date.getMinutes());
//If 4h-2min => 04:02
//If 20h-15min => 20:15
Nekå

Método de fecha de JavaScript

var d= new Date();
d.getFullYear();//Get the year as a four digit number (yyyy)
d.getMonth();//Get the month as a number (0-11)
d.getDate();//Get the day as a number (1-31)
d.getHours();//Get the hour (0-23)
d.getMinutes();//Get the minute (0-59)
d.getSeconds();//Get the second (0-59)
d.getMilliseconds();//Get the millisecond (0-999)
d.getTime();//Get the time (milliseconds since January 1, 1970)
Grepper

Fecha y hora en JavaScript

var dateWithTime = new Date().toLocaleString().replace(",", "")
console.log(dateWithTime)  
//output :6/24/2022 9:36:33 PM
Scary Snake

Fecha y hora JavaScript

// To test a function and get back its return
function printElapsedTime(fTest) {
  let nStartTime = Date.now(),
      vReturn = fTest(),
      nEndTime = Date.now()

  console.log(`Elapsed time: ${ String(nEndTime - nStartTime) } milliseconds`)
  return vReturn
}

let yourFunctionReturn = printElapsedTime(yourFunction)
Hamzeh Asakereh

Respuestas similares a “Fecha y hora JavaScript”

Preguntas similares a “Fecha y hora JavaScript”

Más respuestas relacionadas con “Fecha y hora JavaScript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código