Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-09-2009, 06:53 AM   PM User | #1
rcod
New to the CF scene

 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rcod is an unknown quantity at this point
Time and Date indications in 2 Digits

Hello,
I've obtained the following code.

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.
rcod is offline   Reply With Quote
Old 12-09-2009, 07:57 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here you are:-

Code:
<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
Philip M is offline   Reply With Quote
Old 12-09-2009, 11:29 AM   PM User | #3
rcod
New to the CF scene

 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rcod is an unknown quantity at this point
It works!
Thank you very much for your quick and helpful assistance.
rcod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:37 AM.


Advertisement
Log in to turn off these ads.