Dia 34
This commit is contained in:
101
Practicas/Practicas JS/Introduccion/11_DATE_Javascript.html
Normal file
101
Practicas/Practicas JS/Introduccion/11_DATE_Javascript.html
Normal file
@@ -0,0 +1,101 @@
|
||||
<!Doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>OBJETO DATE JAVASCRIPT</title>
|
||||
<script type="text/javascript">
|
||||
|
||||
var meses = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
|
||||
|
||||
var dias = ["Domingo","Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"];
|
||||
|
||||
|
||||
// Bibliotecas de objetos javascript
|
||||
|
||||
// Clase Date valores del tipo fecha
|
||||
// Fecha de hoy
|
||||
//new Date() Tue Jan 23 2024 19:13:13 GMT+0100
|
||||
//Date.now() hora actual en milisegundos desde el 1 de Enero de 1970, 00:00:00 UTC
|
||||
|
||||
|
||||
/*
|
||||
getDate() Devuelve el día del mes.
|
||||
getDay() Devuelve el día de la semana.(lunes 1, martes 2, ...)
|
||||
getHours() Retorna las horas. En 24H.
|
||||
getMinutes() Devuelve los minutos.
|
||||
getMonth() Devuelve el mes (atención al mes que empieza por 0 Enero).
|
||||
getSeconds() Devuelve los segundos.
|
||||
getTime() Devuelve los milisegundos desde 1970
|
||||
getFullYear() Retorna el año con 4 dígitos.
|
||||
-----
|
||||
setDate() Actualiza el día del mes.
|
||||
setHours() Actualiza la hora.
|
||||
setMinutes() Cambia los minutos.
|
||||
setMonth() Cambia el mes.
|
||||
setSeconds() Cambia los segundos.
|
||||
setTime() Actualiza la fecha completa en milisegundos
|
||||
setFullYear() Cambia el año 4 dígitos
|
||||
*/
|
||||
|
||||
var fechahoy=new Date();
|
||||
var fechaM=Date.now();
|
||||
document.write( "hoy es "+fechahoy);
|
||||
document.write("<br>");
|
||||
document.write( "hoy es "+fechaM);
|
||||
document.write("<br>");
|
||||
document.write(Date.now());
|
||||
document.write("<br>");
|
||||
// Fijar una fecha
|
||||
//miFecha = new Date(año,mes,dia,hora,minutos,segundos,milisegundos)
|
||||
//miFecha = new Date(año,mes,dia)
|
||||
var fecha =new Date(2020,5,1); //En UTC sin tener en cuenta la diferencia horaria
|
||||
var fecha2 = new Date("2020-06-01");
|
||||
var fecha3 = new Date("2020-06-01T00:00:00Z");
|
||||
//console.log(fecha,fecha2);
|
||||
//console.log(fecha.toISOString()); // "2020-06-01T00:00:00.000Z"
|
||||
//console.log(fecha2.toISOString()); // "2020-06-01T00:00:00.000Z"
|
||||
//console.log(fecha3.toISOString()); // "2020-06-01T00:00:00.000Z"
|
||||
|
||||
// Pasar a milisegundos
|
||||
var milFe=fecha.getTime();
|
||||
document.write("<br>fecha " +fecha);
|
||||
document.write("<br>");
|
||||
document.write("<br>fecha " +milFe);
|
||||
document.write("<br>");
|
||||
document.write(" <br>este mes es "+meses[fecha.getMonth()]) ;
|
||||
document.write("<br>");
|
||||
document.write("<br> Hoy es "+dias[fechahoy.getDay()]);
|
||||
document.write("<br>");
|
||||
var date = new Date(872817240000);
|
||||
document.write("<br>"+date);
|
||||
document.write("<br>");
|
||||
|
||||
// valueAsNumber sacar fecha de input "date" en milisegundos
|
||||
//salida=document.getElementById("fecha").valueAsNumber;
|
||||
|
||||
// .toDateString() Devuelve formato sólo de fecha: Fri Aug 24 2018
|
||||
// .toLocaleDateString() Idem al anterior, pero en el formato regional actual: 24/8/2018
|
||||
|
||||
// Clase Math: permite representar y realizar cálculos matemáticos
|
||||
// max y min para valor máximo y minimo
|
||||
document.write("valor máximo "+Math.max(7,3,9)) ;
|
||||
document.write("<br>");
|
||||
// round redondeo
|
||||
document.write("<br>valor redondeado con ROUND "+ Math.round(7.43));
|
||||
document.write("<br>");
|
||||
// Redondeo al alza
|
||||
document.write("<br>valor redondeado con CEIL "+ Math.ceil(7.33));
|
||||
document.write("<br>");
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<input type="date" id="fecha" value="2024-02-24"/>
|
||||
<script>
|
||||
let fechaInput=document.getElementById("fecha").valueAsNumber;
|
||||
console.log(fechaInput);
|
||||
var fechaActual = new Date(); // Fecha y hora actuales
|
||||
console.log(fechaActual);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user