PDA

View Full Version : My date problem continues :(



winpeace
11-13-2006, 01:57 PM
Date: <br>
<input type="text" id="date_put" name="date" style="width:300px;" class="inputbox" value="" validate="blank">
<script type="text/javascript">document.getElementById('date_put').value=new Date().toLocaleDateString();</script>
<br>



I add this codes my comment component
1-How to add this code time like 15:53
2-And another problem when the explorer refresh the coming date and coming time;the date and the time is change too.So how the date(and the time) is stop changing coming times and coming date

Acey99
11-13-2006, 07:33 PM
Date: <br>
<input type="text" id="date_put" name="date" style="width:300px;" class="inputbox" value="" validate="blank">
<script type="text/javascript">document.getElementById('date_put').value=new Date().toLocaleDateString();</script>
<br>



I add this codes my comment component
1-How to add this code time like 15:53
2-And another problem when the explorer refresh the coming date and coming time;the date and the time is change too.So how the date(and the time) is stop changing coming times and coming date


ok, so you want a clock on your page huh ?


<head>
<!-- style clock however you want -->
<style>
#myclock{ width:100px; height:20px; border:1px solid #000; color:#000; text-align:center; position:absolute; top:0px; left:0px; }
</style>
<script language="JavaScript" type="text/javascript">
<!--
function dClock(){
var t = new Date();
var hours= t.getHours();
var minutes= t.getMinutes();
var seconds= t.getSeconds();
var timeStr= "" + hours;
timeStr+= ((minutes < 10) ? ":0" : ":") + minutes;
timeStr+= ((seconds < 10) ? ":0" : ":") + seconds;

var timeObject = (document.all) ? document.all["myclock"] : document.getElementById("myclock");
timeObject.innerHTML = timeStr;
Timer= setTimeout("dClock()",1000);
}
//-->
</script>


</head>

<body onload="dClock()">

<div id="myclock"><div>


</body>

winpeace
11-14-2006, 06:51 AM
not this :(

tech_support
11-15-2006, 06:03 AM
Like this?



var date = new Date()
var fullDate = date.toLocaleDateString();
var hours = date.getHours()
var minutes = date.getMinutes()
if (minutes<10)
var time = hours + ":0"+minutes
else
var time = hours + ":" + minutes

document.getElementById('date_put').value=fullDate+" "+time
document.getElementById('date_put').size=document.getElementById('date_put').value.length+5

Remember to put a function inside it. eg:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Date and Time</title>
</head>

<body>
<script type="text/javascript">
window.onload=function(){
var date = new Date()
var fullDate = date.toLocaleDateString();
var hours = date.getHours()
var minutes = date.getMinutes()
if (minutes<10)
var time = hours + ":0"+minutes
else
var time = hours + ":" + minutes

document.getElementById('date_put').value=fullDate+" "+time
document.getElementById('date_put').size=document.getElementById('date_put').value.length+5
}
</script>
<input type="text" id="date_put">
</body>
</html>




2-And another problem when the explorer refresh the coming date and coming time;the date and the time is change too.So how the date(and the time) is stop changing coming times and coming date

Well, obviously time changes doesn't it? :p