“Retourner la date actuelle en javascript” Réponses codées

Retourner la date actuelle en javascript

let today = new Date().toLocaleDateString()

console.log(today)
Poor Polecat

Date javascript Obtenir la date actuelle

var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
//var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date+' '+time;
The dateTime variable contains result as:

2018-8-3 //11:12:40
Exuberant Elk

Obtenez la date d'aujourd'hui JavaScript

var today = new Date();

var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
Hastings Keith

Comment obtenir la date actuelle dans JS

let today = new Date();
let month = today.getMonth() + 1;
month = month < 10 ? "0" + month : month;
let days = today.getDate() < 10 ? "0" + today.getDate() : today.getDate();

today = today.getFullYear() + "-" + month + "-" + days;

console.log(today);
Indonesia People

Obtenez la date d'aujourd'hui JavaScript

var today = new Date();
Joyous Jaguar

Obtenez la date d'aujourd'hui dans JS

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

Réponses similaires à “Retourner la date actuelle en javascript”

Questions similaires à “Retourner la date actuelle en javascript”

Plus de réponses similaires à “Retourner la date actuelle en javascript” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code