/    Sign up×
Community /Pin to ProfileBookmark

Help with Date and Time.

Hi guys,

I have JavaScript code that displays the date, time and URL in the web page, here is the code:

Code:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<title>JavaScript Page One</title>
</head>
<body>
<script type=”text/javascript”>
var today=new Date()
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

document.write(”+today.toString()+'<br>’+window.location+”)
document.write(“<br />”);
document.write(“Browser name: “+ browser);
document.write(“<br />”);
document.write(“Browser version: “+ version);
</script>
</body>
</html>
How can i format it so that it uses the following colors for different date and time components: Day in red, Date in green, Month in yellow, Year in blue, Hours and Minutes in brown?

And also, what is the JavaScript code to successfully display the number of forms, anchors and links in the page?

Thanks

~Savage

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@myrtle1908Sep 30.2009 — How can i format it so that it uses the following colors for different date and time components: Day in red, Date in green, Month in yellow, Year in blue, Hours and Minutes in brown?[/QUOTE]

Here's a quick and dirty example. Ultimately you should get your hands on a decent date library.

[code=php]<html>
<head>
<title>Colour Clock</title>
<style>
#clock {padding:10px; border:1px solid black; font-weight:bold}
#day {color:red}
#date {color:green}
#month {color:yellow}
#year {color:blue}
#hm {color:brown}
</style>
<script type="text/javascript">
function fmt(n) {
return ((n<10)?'0'+n:n);
}
function showClock() {
// Day in red, Date in green, Month in yellow, Year in blue, Hours and Minutes in brown
var days = 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(',');
var months = 'January,February,March,April,May,June,July,August,September,October,November,December'.split(',');
var now = new Date();
var m = now.getMonth()+1;
var month = months[m]; m = fmt(m);
var d = fmt(now.getDate());
var day = days[now.getDay()];
var year = now.getFullYear();
var date = d + '/' + m + '/' + year; // UK format
var hours = fmt(now.getHours());
var mins = fmt(now.getMinutes());
var d = document;
d.getElementById('day').innerHTML = day;
d.getElementById('date').innerHTML = date;
d.getElementById('month').innerHTML = month;
d.getElementById('year').innerHTML = year;
d.getElementById('hm').innerHTML = hours+':'+mins;

}
</script>
</head>
<body onload="showClock();">
<div id="clock">
<div id="day"></div> <div id="date"></div> <div id="month"></div> <div id="year"></div> <div id="hm"></div>
</div>
</body>
</html> [/code]



And also, what is the JavaScript code to successfully display the number of forms, anchors and links in the page?[/QUOTE]


Forms

[code=php]document.getElementsByTagName('form').length;[/code]

Links

[code=php]document.getElementsByTagName('a').length;[/code]

Good luck.
×

Success!

Help @Savage87 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,
)...