+ Reply to Thread
Results 1 to 5 of 5

Thread: Displaying Time & Date Through JavaScript/HTML

  1. #1
    DJL2K is offline x10Hosting Member DJL2K is an unknown quantity at this point
    Join Date
    Aug 2005
    Posts
    6

    Displaying Time & Date Through JavaScript/HTML

    Displaying Time and Date through JavaScript

    I'm gonna start off by guessing you all know how to start off JavaScript - with <script language="JavaScript"></script> for all you people who don't know.

    Date
    Well inside the <script> tags for the basic date in an alert put this:
    Code:
    <script language="JavaScript">
    var now = new Date();
     
    alert( now );
    </script>
    That will give you:


    Now of course not everyone wants that do they? So that's when it get's an awful lot more complicated.
    Code:
    <script language="JavaScript">
    var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
     
    var mons = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
     
    var now=new Date();
     
    var yy = now.getYear();
     
    varmm = now.getMonth(); mm=mons[mm];
     
    var dd = now.getDate();
     
    var dy = now.getDay();	day=days[dy];
     
    alert(dy+" "+dd+" "+mm+" "+yy);
    </script>
    And that will give you this:


    Time

    If you want a basic (I say basic but it's rather hard!) time information alert you'll want this:
    Code:
    <script language="JavaScript">
    var now = new Date();
     
    var hh = now.getHours();
     
    var mn = now.getMinutes();
     
    var ss = now.getSeconds();
     
    var ms = now.getMilliseconds();
     
    var hi = "Good Morning";
     
    if( hh > 11 ) hi= "Good Afternoon";
     
    if( hh > 17 ) hi= "Good Evening";
     
    var tim = hi + "\n";
     
    tim += "Hours: " +hh+ "\n";
     
    tim += "Minutes: " +mn+ "\n";
     
    tim += "Seconds: " +ss+ "." +ms;
     
    alert(tim);
    </script>
    That will give you this:


    JavaScript Clock

    The script below displays the time according to your computer in an HTML form text input.

    Code:
    <body onLoad="tick()">
    <script language="JavaScript">
    <!--
     
    function tick(){
    var now = new Date();
    var hh = now.getHours();	if( hh <= 9 ) hh = "0" + hh;
    var mn = now.getMinutes(); if( mn<= 9 ) mn = "0" + mn;
    var ss = now.getSeconds(); if( ss <= 9 ) ss = "0" + mn;
    var tt = hh + ": " +mn+ ": " + ss;
    document.f.clock.value = tt;
    window.setTimeout( "tick()", 1000 );
    }
     
    // -->
    </script>
    <form name="f">
    <input name="clock" type="text" size="10">
    </form>
    </body>
    That code will give you this (with the current time):


    I Hope This is of some use to you. Remember! JavaScript is case sensitive so be very careful. Also try not to delete any of the brackets or semi-colons or the scripts won't work.
    Last edited by DJL2K; 09-01-2005 at 10:52 AM.

  2. #2
    03moscropl's Avatar
    03moscropl is offline Flash Freak 03moscropl is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    England
    Posts
    349

    Re: Displaying Time & Date Through JavaScript/HTML

    theres more like that at dynamicdrive.com :kdubb:
    my customised games module for phpnuke
    http://dragongamer.net/modules.php?name=arcade

  3. #3
    Bl33dsnom0r3 is offline x10Hosting Member Bl33dsnom0r3 is an unknown quantity at this point
    Join Date
    Jul 2005
    Posts
    55

    Re: Displaying Time & Date Through JavaScript/HTML

    Nice! I rpolly wont use. But good job.



  4. #4
    Woolie's Avatar
    Woolie is offline x10 Lieutenant Woolie is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    The Fletcher Memorial
    Posts
    431

    Re: Displaying Time & Date Through JavaScript/HTML

    To be honest, i'd just turn away from a site that had the time pop up at me when it loaded.

  5. #5
    flapietoetoe is offline x10 Sophmore flapietoetoe is an unknown quantity at this point
    Join Date
    Aug 2005
    Posts
    113

    Re: Displaying Time & Date Through JavaScript/HTML

    yeah ,
    there might be some smart coder behind the alert, but it still looks kinda n00bie like those freewebs stuf that u can put on ur website like a mouse being trailed by the time (always hated that)

+ Reply to Thread

Similar Threads

  1. Replies: 4
    Last Post: 01-05-2006, 10:27 AM
  2. Time out prob
    By elserge82 in forum Free Hosting
    Replies: 6
    Last Post: 11-29-2005, 07:04 PM
  3. More time to create website
    By -Daniel in forum Feedback and Suggestions
    Replies: 6
    Last Post: 07-03-2005, 04:34 PM
  4. Cannot acces website and forums most of time
    By dbforum in forum Free Hosting
    Replies: 20
    Last Post: 03-06-2005, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers