/    Sign up×
Community /Pin to ProfileBookmark

Working with date and time

Hi,

I have tried to create this code below to give me the format like below

Wednesday 17th May 2006, 00:51 AM

[CODE]
<script type=”text/javascript”>
var d=new Date()
var weekday=new Array(“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”)
var monthname=new Array(“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”)
var Hours;
var Mins;
var Time;
var FullString;
Hours = Stamp.getHours();

if (Hours >= 12) {
Time = ” P.M.”;
} else {
Time = ” A.M.”;
}

if (Hours > 12) {
Hours -= 12;
}

if (Hours == 0) {
Hours = 12;
}

Mins = Stamp.getMinutes();

if (Mins < 10) {
Mins = “0” + Mins;
}

FullString = weekday[d.getDay()] + ” ” + d.getDate() + “. ” + monthname[d.getMonth()] + ” ” + d.getFullYear() + “, ” + Hours + “:” + Mins + Time;
document.write(FullString);

</script>
[/CODE]

Instead all i get is blank – nothing ?.

Any ideas?

Thanks
Adam

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMay 16.2006 — Do you have PHP on your server? If so you should use it with [url=http://au.php.net/manual/en/function.date.php]date[/url]
[code=php]echo date("l jS F Y, h A");[/code]
Copy linkTweet thisAlerts:
@mrhooMay 17.2006 — In your code I see " Hours = Stamp.getHours();"

Where did Stamp come from?

You know if you just call:

[CODE]var d=new Date()
var s=d.toLocaleDateString()+' '+d.toLocaleTimeString();[/CODE]


you get output for s like: [B]"Wednesday, May 17, 2006 12:51:03 AM"[/B]

And you can modify the Date.prototype methods.
×

Success!

Help @k0r54 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.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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