Jump to content

Automatic Date & time


LittleNicky

Recommended Posts

Hi i was just reading and i decided it would be nice to put it on my site, anyway of course a few problems arised it said my time was 11:00am when its 7:00pm, anyway i was wondeirng is their anyway that you can make it read from the users pc clock?Also this is not as imporant but can u make it automatcially refresh after 1 minute?Thanks-Jny Mrs

Link to comment
Share on other sites

you need javascript to get the clients pc time.use this

<html><head>	<title>JavaScript Date and Time</title>	<script type="text/javascript">					function writeDateTime()		{			var dateo = new Date();			var th = document.getElementById('timeHolder');			th.innerHTML = getDateNow(dateo) + " " + getTimeNow(dateo);			setTimeout(writeDateTime,1000);		}				function getDateNow(dateo)		{			return dateo.getDay() + "/" + dateo.getMonth() + "/" + dateo.getYear();		}				function getTimeNow(dateo)		{			var hr = dateo.getHours();			var min = dateo.getMinutes();			var sec = dateo.getSeconds();						if(hr > 12) hr = hr - 12;			if(min < 10) min = "0" + min;			if(sec < 10) sec = "0" + sec;			return hr + ":" + min + "." + sec;		}		</script></head><body>	<div id="timeHolder"></div>	<script>		writeDateTime();	</script></body></html>

Link to comment
Share on other sites

Use java script: http://www.w3schools.com/jsref/jsref_obj_date.asp (like aspnetguy just said before me).I have some code to show the date, day and clock, updates each second:

<script type="text/javascript"><!--//var myMonths=new Array("January","February","March","April","May","June","July","August","September","October","November","December");var myDays= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");today=new Date();thisDay=myDays[today.getDay()];thisMonth=myMonths[today.getMonth()];thisYear=today.getFullYear();thisDate=today.getDate();todaysDate=thisDay+", "+thisDate+" "+thisMonth+" "+thisYear;function myClock(){today=new Date();var theHours=today.getHours();if (theHours>11){theTimeSuffix="PM";}if (theHours>12)var theHours=theHours-12;else{theTimeSuffix="AM";}var theMinutes=today.getMinutes();if (theMinutes<10)var theMinutes="0"+theMinutes;var theSeconds=today.getSeconds();if (theSeconds<10)var theSeconds="0"+theSeconds;var theTimeNow=theHours+":"+theMinutes+":"+theSeconds+" "+theTimeSuffix;//document.formTime.textTime.value=theTimeNow;document.getElementById('time').innerHTML=theTimeNow;}var clockWork=setInterval("myClock()",1000);//--></script><script type="text/javascript"><!--document.write(todaysDate);//--></script>- <span id="time"></span>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...