...

View Full Version : to display current date and time using javascript



sakee123
12-13-2007, 07:47 AM
hi, all
i want to display the current date and time on click a button in a textbox

As shown below diagram



C:\Documents and Settings\Administrator\Desktop\untitled.bmp

with two buttons one to increment hours when the cursor is on hours ,minutes,seconds,....


Please do help:)

oesxyl
12-13-2007, 08:01 AM
hi, all
i want to display the current date and time on click a button in a textbox

As shown below diagram

C:\Documents and Settings\Administrator\Desktop\untitled.bmp

the diagram is not available!



with two buttons one to increment hours when the cursor is on hours ,minutes,seconds,....

Please do help:)
if is "current" why do you need to increment?

Kor
12-13-2007, 08:44 AM
One more question... You need the current data of the server? Or the user's current data?

sakee123
12-13-2007, 09:08 AM
hi,

I want the time and date similar to system clock(taskbar-rightside) in which time is displayed with up&down buttons to increse and decrese hours,minutes,etc
Please do help

Thanks
Ravi

sakee123
12-13-2007, 09:10 AM
hi,thannks
i need users current data

Byeeeeee

Kor
12-13-2007, 12:39 PM
Like this?:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var setTim=false;
function initClock(h,m,s){
if(setTim){clearTimeout(setTim)}
var date=new Date();
date.setHours(date.getHours()+h);
date.setMinutes(date.getMinutes()+m);
date.setSeconds(date.getSeconds()+s);
startClock(date);
}
function startClock(date){
date.setSeconds(date.getSeconds()+1);
var H=date.getHours();H<10?H='0'+H:null;
var M=date.getMinutes();M<10?M='0'+M:null;
var S=date.getSeconds();S<10?S='0'+S:null;
var mySpan=document.getElementById('myspan');
mySpan.innerHTML=H+' : '+M+' : '+S;
setTim=setTimeout(function(){startClock(date)},1000)
}
function changeTime(f){
var h,m,s;
h=isNaN(f['ho'].value)?0:Number(f['ho'].value);
m=isNaN(f['mi'].value)?0:Number(f['mi'].value);
s=isNaN(f['se'].value)?0:Number(f['se'].value);
initClock(h,m,s);
}
onload=function(){
initClock(0,0,0);
}
</script>
</head>
<body>
<span id="myspan"></span>
<br>
<br>
<form action="">
<input type="text" name="ho"><input type="button" value="Change Hours" onclick="changeTime(this.form)">
<br>
<br>
<input type="text" name="mi"><input type="button" value="Change Minutes" onclick="changeTime(this.form)">
<br>
<br>
<input type="text" name="se"><input type="button" value="Change Seconds" onclick="changeTime(this.form)">
</form>
</body>
</html>

sakee123
12-14-2007, 04:55 AM
hi,KOR
Thanks for the reply,i want different functionality...

I have pasted the code below....

When cursor is on hours and if you press + button it should be incremented by 1 every time and when you press - it should be decremented by 1...

The same case with minutes also....
<HTML>
<HEAD>
<script type="text/javascript">
<script language="javascript" type="text/javascript">
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime ()
{
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}

function showtime1()
{
var now = new Date();
var hours1 = now.getHours();

var hh= parseInt(hours1);

var hours=hh+1;


var minutes = now.getMinutes();
var seconds = now.getSeconds()

var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds

document.clock.face.value = timeValue;
timerID = setTimeout("showtime1()",1000);
timerRunning = true;
}

function startclock(id) {
if(id==1)
{

showtime1();
}
else
{

showtime();
}

}


</SCRIPT>
<FORM name="clock">
<input type="text" name="face" size=13 value="">
<input type="button" value="button" id="0" onClick="startclock(id)">
<input type="button" value="+" onClick="Inc">
<input type="button" value="-" onClick="Inc">
</FORM>
</HTML>





Byeeeeeee

Kor
12-14-2007, 08:23 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var setTim=false;
var incVar=0;
function initClock(h){
var H=h+incVar;
if(setTim){clearTimeout(setTim)}
var date=new Date();
date.setHours(date.getHours()+H);
incVar+=h;
startClock(date);
}
function startClock(date){
date.setSeconds(date.getSeconds()+1);
var H=date.getHours();H<10?H='0'+H:null;
var M=date.getMinutes();M<10?M='0'+M:null;
var S=date.getSeconds();S<10?S='0'+S:null;
var mySpan=document.getElementById('myspan');
mySpan.innerHTML=H+' : '+M+' : '+S;
setTim=setTimeout(function(){startClock(date)},1000)
}
function changeTime(f){
var h,m,s;
h=isNaN(f['ho'].value)?0:Number(f['ho'].value);
m=isNaN(f['mi'].value)?0:Number(f['mi'].value);
s=isNaN(f['se'].value)?0:Number(f['se'].value);
initClock(h,m,s);
}
onload=function(){
initClock(0);
}
</script>
</head>
<body>
<span id="myspan"></span>
<br>
<br>
<form action="">
<input type="button" value="+" onclick="initClock(1)">
<input type="button" value="-" onclick="initClock(-1)">

</form>
</body>
</html>

sakee123
12-15-2007, 04:58 AM
hi,KOR

Thanks for the reply...


Display the time in a text box...

When cursor is on hours and if you press + button it should be incremented by 1...

When cursor is on minutes and if you press + button it should be incremented by 1...

Thnking you..

RAvi..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum