Ejemplo 1: javascript horas minutos segundos
var myDate = new Date().toTimeString().replace(/.*(d{2}:d{2}:d{2}).*/, "$1");
console.log(myDate)
//using regex
Ejemplo 2: javascript obtiene la hora a partir de la fecha
var myDate = new Date(2019, 11, 24, 10, 33);
var hour = myDate.getHours();
Ejemplo 3: new Date () obtiene horas específicas min seg
new Date().getDate() // Get the day as a number (1-31)
new Date().getDay() // Get the weekday as a number (0-6)
new Date().getFullYear() // Get the four digit year (yyyy)
new Date().getHours() // Get the hour (0-23)
new Date().getMilliseconds() // Get the milliseconds (0-999)
new Date().getMinutes() // Get the minutes (0-59)
new Date().getMonth() // Get the month (0-11)
new Date().getSeconds() // Get the seconds (0-59)
new Date().getTime() // Get the time (milliseconds since January 1, 1970)
Ejemplo 4: javascript horas minutos segundos
String.prototype.toHHMMSS = function () {
var sec_num = parseInt(this, 10); // don't forget the second param
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
return hours+':'+minutes+':'+seconds;
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)