Dev Faq
6
votes

Obtenir la date d'aujourd'hui en JavaScript

Comment puis-je obtenir la date actuelle en JavaScript dans ce format?

"M / D / AAAAA"?

Merci.

Si ce serait aujourd'hui, ce serait

"2/17/2011", si c'était le 3ème, ce serait "2/3/2011".

merci

javascript

1 commentaires

Avez-vous déjà vérifié les docs? - développeur.mozilla.org/fr/javaScript/reference/global_Objects / ... << / a>


3 Réponses :


15
votes
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
I assigned each part into its own variable for this example so that it's more clear as to what it returns.

0 commentaires

3
votes

Utilisez la date JavaScript DATE CODE> Objet:

var d = new Date();
alert((d.getMonth() + 1) + '/' + d.getDate() + '/' + d.getFullYear());


0 commentaires

1
votes

STEVEN STEVITAN'S (STEVENLEVITHAN.COM) La fonction DateFormat est vraiment polyvalente pour moi.

voir: p>

http://blog.stevenlevithan.com / Archives / Date-Time-Format P>

Dans son code, il ajoute DateFormat en tant que méthode de prototype de date. P>

var now = new Date();

var variable=now.format("m/dd/yy");

document.write(variable);


0 commentaires

Articles qui pourrait vous intéresser :

Impossible d'importer le module "@ angular / material"
Interaction profonde avec break and catch
Utilisation de node.js comment renommer tous les fichiers d'un dossier
Google Chrome Uncaught (promis) DOMException lors de la lecture AUDIO
© 2020 www.devfaq.fr - Licensed under  cc by-sa 3.0  with  attribution required.