Jump to content

JavaScript and Date


emmaspeedy

Recommended Posts

HI, I have a little question for you guys. I want to display de date thanks to Javascrip. I can display it but !!! it display this --> 2015313 and i want this --> 2015/3/13 how can introduce the " / ". I have try everything but nothing seems to work. Here is that I have now :

 

<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
function InstallHeader( NomPage ) {
document.getElementById("Entête").innerHTML=NomPage;
}
function InstallDate( ) {
var a = new Date().getFullYear();
var m = new Date().getMonth();
var j = new Date().getDate();
document.getElementById("Date").innerHTML+=a;
document.getElementById("Date").innerHTML+=m;
document.getElementById("Date").innerHTML+=j;
}
</script>
<style>
#Entête { padding-left:2%; background-color:lightgray; width:85%; float:left; }
#Date { background-color:lightblue; width:13%; float:left; text-align:center;
}
</style>
</head>
<body>
<div id="Entête"> </div> <div id="Date"> </div>
<script type="text/javascript"> InstallHeader("Titre de la page"); InstallDate();</script>
</body>
</html>
Link to comment
Share on other sites

I have try everything

I seriously doubt that.This is where you write the text:
document.getElementById("Date").innerHTML+=a;document.getElementById("Date").innerHTML+=m;document.getElementById("Date").innerHTML+=j;
You can add any additional text you want there.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...