Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile to display current date and time using javascript

    hi, all
    i want to display the current date and time on click a button in a textbox

    As shown below diagram



    [IMG]C:\Documents and Settings\Administrator\Desktop\untitled.bmp[/IMG]

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


    Please do help

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by sakee123 View Post
    hi, all
    i want to display the current date and time on click a button in a textbox

    As shown below diagram

    [IMG]C:\Documents and Settings\Administrator\Desktop\untitled.bmp[/IMG]
    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?

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    One more question... You need the current data of the server? Or the user's current data?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,thannks
    i need users current data

    Byeeeeee

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Like this?:
    Code:
    <!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>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    <!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>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •