Click to See Complete Forum and Search --> : simple javascript for date
floriauck
09-06-2003, 01:29 PM
Hi,
I am a graphic designer and I have no clue about javascript. For this project though, I need a simple script that outputs the current date ... in the form of 03.09.2003
Day.Month,Year .
Can somebody send me this little script? that would be great,
thanks
florian
Khalid Ali
09-06-2003, 02:09 PM
Here you go a complete working example
<script type="text/javascript">
<!--
Date.prototype.getDMYDate = function(){
function formatDate(val){
return (val<10)?"0"+val:val;
}
return formatDate(this.getDate())+"."+formatDate(this.getMonth()+1)+"."+this.getFullYear();
}
function Process(){
alert((new Date()).getDMYDate());
}
//-->
</script>
</head>
<body class="body">
<form id="form1" action="" onsubmit="">
<input type="button" value="Get Date" onclick="Process()"/>
</form>
floriauck
09-06-2003, 02:16 PM
oh, wow.. thanks a lot for the script ...
is there any way that i could display the date right in my website without having to click on the GET DATE button ? that would be perfect ..
thanks so much for your help !
florian
Khalid Ali
09-06-2003, 02:23 PM
replace your existing body tag with the one below
<body onload="Process()">
mind you,if you want to write this date somewhere in the document then you will have to add the line below in your document where you want to add the date
<div id="dateDiv"></div>
once thats done then you will need to remove the alert and instead of that add this line
function Process(){
//alert((new Date()).getDMYDate());
document.getElementById("dateDiv").innerHTML = ((new Date()).getDMYDate());
}
floriauck
09-06-2003, 02:48 PM
awesoem, i really got it to work .... One last question, is there any way of changing the color or the text that get displayed to white ?? and change the font ?
thanks one more time for your time and help
Khalid Ali
09-06-2003, 03:59 PM
yes set the style for the div element such as
<div id="dateDiv" style="color:green;font-weight:bold;font-size:12px;"></div>
floriauck
09-07-2003, 05:48 AM
Hi,
I think I will start to study some programming. It might be very useful for me in the future too. If you want to see what I did with the script from khalid ali check out
www.future-invest.com
Khalid Ali, thank you very much for your help ... if u ever need any help with graphics, etc, dont hesitate to ask,,
florian
Khalid Ali
09-07-2003, 08:22 AM
Thanks and you are most welcome...:)