...

View Full Version : Time and Date indications in 2 Digits



rcod
12-09-2009, 06:53 AM
Hello,
I've obtained the following code.



function makeDate(){
var d = new Date();
var strDate=d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate() + " ";
strDate += d.getHours() + ":" + d.getMinutes() +":"+ d.getSeconds() ;
return strDate;


and I think I'm going to get the time and date indications in 2 digits.

I want to get it like this:
2009/12/07 18:07:33

NOT like:
2009/12/7 18:7:33

How should I alter the code?
Can anyone help?

Thanks in advance.

Philip M
12-09-2009, 07:57 AM
Here you are:-


<script type = "text/javascript">

function makeDate() {
var d = new Date();
var mn = d.getMonth()+1; if (mn <10) {mn = "0" + mn}
var dt = d.getDate(); if (dt <10) {dt = "0" + dt}
var hr = d.getHours(); if (hr <10) {hr = "0" + hr}
var mins = d.getMinutes(); if (mins < 10) {mins = "0" + mins}
var secs = d.getSeconds(); if (secs <10) {secs = "0" + secs}
var strDate = d.getFullYear() + "/" + mn + "/" + dt + " " + hr + ":" + mins + ":" + secs
return strDate;
}

</script>


I don't pretend we have all the answers. But the questions are certainly worth thinking about.. - Arthur C. Clarke quotes (English Writer of science fiction, b.1917

rcod
12-09-2009, 11:29 AM
It works!
Thank you very much for your quick and helpful assistance.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum