/    Sign up×
Community /Pin to ProfileBookmark

Need help from a javascript coder

I have on my website a small I thought simple javascript. It is to display the date and time. It displays it.. but it is a month behind .. Today is December 23rd, 2008 and it shows November 23, 2008. Now I thought it was my computer.. but my date on my computer is fine… So why is it showing a date from a month ago?

<script type=”text/javascript”>

var currentDate = new Date()
var month = currentDate.getMonth()

var day = currentDate.getDate()
var year = currentDate.getFullYear()
document.write(“<b>” + month + “/” + day + “/” + year + “</b>”)
</script> – <script type=”text/javascript”>
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

var suffix = “AM”;
if (hours >= 12) {
suffix = “PM”;
hours = hours – 12;
}
if (hours == 0) {
hours = 12;
}

if (minutes < 10)
minutes = “0” + minutes

document.write(“<b>” + hours + “:” + minutes + ” ” + suffix + “</b>”)
</script>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mscactusauthorDec 24.2008 — You may want to look at the website to see this for yourself.

http://www.bighousebarn.com
Copy linkTweet thisAlerts:
@SephrDec 24.2008 — Change the month variable line to this:

var month = currentDate.getMonth() + 1;

There are 12 months but the first one starts out at the number 0 in getMonth().
Copy linkTweet thisAlerts:
@mscactusauthorDec 24.2008 — Thank you so VERY much, and Merry Christmas to you. You just saved an old lady one more grey hair. !! It works great now.
×

Success!

Help @mscactus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...