Results 1 to 4 of 4

Thread: My date problem continues :(

  1. #1
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question My date problem continues :(

    Code:
    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

  2. #2
    Join Date
    Nov 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by winpeace View Post
    Code:
    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 ?
    Code:
    <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>

  3. #3
    Join Date
    Nov 2006
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    not this

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Like this?

    Code:
    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:

    Code:
    <!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>
    Quote Originally Posted by winpeace
    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?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

Bookmarks

Posting Permissions

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