“Obtener fecha en JavaScript” Código de respuesta

JavaScript obtenga fecha

let date = new Date(); //actual time in miliseconds
let string = date.toString();
// expected output: Wed Jul 28 1993 14:39:07 GMT+0200 (CEST)
// if you need more power: date-fns.js or moment.js
CharllierJr

Métodos 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

Obtener fecha en JavaScript

document.write(new Date().getFullYear());
Ambitious Coder

Obtener fecha 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

JavaScript getDate

var d=new Date();
d.getDate(); //returns the day of the month (from 1 to 31)
Grepper

Obtener fecha JavaScript

var objToday = new Date(),
	weekday = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
	dayOfWeek = weekday[objToday.getDay()],
	domEnder = function() { var a = objToday; if (/1/.test(parseInt((a + "").charAt(0)))) return "th"; a = parseInt((a + "").charAt(1)); return 1 == a ? "st" : 2 == a ? "nd" : 3 == a ? "rd" : "th" }(),
	dayOfMonth = today + ( objToday.getDate() < 10) ? '0' + objToday.getDate() + domEnder : objToday.getDate() + domEnder,
	months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
	curMonth = months[objToday.getMonth()],
	curYear = objToday.getFullYear(),
	curHour = objToday.getHours() > 12 ? objToday.getHours() - 12 : (objToday.getHours() < 10 ? "0" + objToday.getHours() : objToday.getHours()),
	curMinute = objToday.getMinutes() < 10 ? "0" + objToday.getMinutes() : objToday.getMinutes(),
	curSeconds = objToday.getSeconds() < 10 ? "0" + objToday.getSeconds() : objToday.getSeconds(),
	curMeridiem = objToday.getHours() > 12 ? "PM" : "AM";
var today = curHour + ":" + curMinute + "." + curSeconds + curMeridiem + " " + dayOfWeek + " " + dayOfMonth + " of " + curMonth + ", " + curYear;

document.getElementsByTagName('h1')[0].textContent = today;
Big Jojo

Respuestas similares a “Obtener fecha en JavaScript”

Preguntas similares a “Obtener fecha en JavaScript”

Más respuestas relacionadas con “Obtener fecha en JavaScript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código