Dia 34
This commit is contained in:
79
Practicas/Practicas JS/DOM 07/index.html
Normal file
79
Practicas/Practicas JS/DOM 07/index.html
Normal file
@@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<script>
|
||||
function muestraFechaMs() {
|
||||
let ms = new Date().getTime();
|
||||
alert(`Fecha en milisegundos: ${ms} `);
|
||||
let manana = new Date();
|
||||
manana.setDate(manana.getDate() + 1);
|
||||
manana.setHours(10, 0, 0, 0);
|
||||
alert(manana.getTime())
|
||||
}
|
||||
|
||||
function fechaFormato() {
|
||||
var diasSemana = ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'];
|
||||
var meses = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'];
|
||||
let fecha = new Date();
|
||||
|
||||
const dia = diasSemana[fecha.getDay()]
|
||||
const mes = meses[fecha.getMonth()]
|
||||
const hora = fecha.getHours();
|
||||
const minutos = fecha.getMinutes();
|
||||
alert(`Hoy es ${dia}, ${fecha.getDate()} de ${mes} de ${fecha.getFullYear()} y son las ${hora}:${minutos}`)
|
||||
}
|
||||
|
||||
function calcularDiasTranscurridos() {
|
||||
var fechaReferencia = new Date('1950-01-01T10:00:00');
|
||||
var fechaActual = new Date();
|
||||
var diferenciaMilisegundos = fechaActual - fechaReferencia;
|
||||
var diasTranscurridos = Math.floor(diferenciaMilisegundos / (1000 * 60 * 60 * 24));
|
||||
alert('Días transcurridos desde el 1 de Enero de 1950 a las 10:00 hasta ahora: ' + diasTranscurridos + ' días.');
|
||||
}
|
||||
|
||||
function calcularDiasFaltantes() {
|
||||
var fechaInput = document.getElementById('fechaInput').value;
|
||||
if (!fechaInput) {
|
||||
alert('Por favor, selecciona una fecha.');
|
||||
return;
|
||||
}
|
||||
var fechaSeleccionada = new Date(fechaInput);
|
||||
var fechaActual = new Date();
|
||||
var diferenciaMilisegundos = fechaSeleccionada - fechaActual;
|
||||
var diasFaltantes = Math.ceil(diferenciaMilisegundos / (1000 * 60 * 60 * 24));
|
||||
var resultadoElement = document.getElementById('resultado');
|
||||
alert('Días faltantes hasta la fecha seleccionada: ' + diasFaltantes + ' días.');
|
||||
}
|
||||
|
||||
function contarMs(){
|
||||
const inicio=new Date();
|
||||
prompt('Introduce el nombre');
|
||||
prompt('Introduce los apellidos');
|
||||
const fin=new Date();
|
||||
const diferenciaMs=fin-inicio;
|
||||
alert(`Has tardado ${diferenciaMs} ms en introducir los datos.`);
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="display: flex; flex-direction: column; width: min-content; gap: 4px; padding: 10px;">
|
||||
<button onclick="muestraFechaMs()">Ahora en Ms</button>
|
||||
<button onclick="fechaFormato()">Frase con hoy</button>
|
||||
<button onclick="calcularDiasTranscurridos()">dias desde 1950</button>
|
||||
<div style="display: flex; width: max-content; gap: 4px;"><button onclick="calcularDiasFaltantes()">Dias que faltan</button> <input type="date" name="fecha"
|
||||
id="fechaInput">
|
||||
</div>
|
||||
<button onclick="contarMs()">Contar Tiempo</button>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user