Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
date and time script JavaScript
Old 02-19-2011, 08:52 PM date and time script JavaScript
matt w's Avatar
Super Talker

Posts: 136
Location: kalamazoo
Trades: 0
If anyone could use a date and time note on their site I patched together this script.

HTML Code:
<html>
<head>
<script type="text/javascript">
/* <![CDATA[ */
function startclock()
{
//getting date, time and year
var currentTime = new Date()
var day = currentTime.getDate()
var year = currentTime.getFullYear()
//associating day numbers with their names
var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
//associating month numbers with their names
var m=new Date();
var month=new Array(11);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
//creating a day, month and year variable
daydate = weekday[d.getDay()]+" "+ month[m.getMonth()]+" "+day+""+", "+ year;

//start time collection
//intitializing final time variable
var totaltime = ""
//getting time values and loading hours and minutes from JS new Date()
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
//initializing am and pm variable
var ampm = "";
//puts "0" in single digit minute values
if (minutes < 10){
minutes = "0" + minutes
}
//sets correct am, pm.
if(hours > 11){
ampm = "pm";
} else {
ampm = "am";
}
//gives hours in 12 hour form
if(hours > 12){
hours = hours-12;
}
//if it is the first hour of the morning sets the hour to "12"
if(hours == 0){
hours = 12;
}

totaltime=hours + ":" + minutes + " "+ampm;

document.getElementById('para1').innerHTML = totaltime;
document.getElementById('para2').innerHTML = daydate;

setTimeout('startclock()',1000);


}
/* ]]> */
</script>
</head>
<BODY onLoad="startclock()">
<div>
Current Time: <div id="para1"></div>
<div id="para2"></div>
</div>
</BODY>

</html>
matt w is offline
Reply With Quote
View Public Profile Visit matt w's homepage!
 
 
Register now for full access!
Reply     « Reply to date and time script JavaScript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46409 seconds with 12 queries