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 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    update the current date

    I have a Javascript display the current date and time. No i want that every sec the date is updated. What do i have to change in my script. Almost tried everything.

    MY SCRIPT
    --------------

    <!--
    function initArray() {
    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++)
    this[i+1] = initArray.arguments[i];
    }


    var dagArray = new initArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

    var maandArray = new initArray("January","February","March","April","May","June","July","August","September","October","N ovember","December");

    var nu = new Date();
    var dagtekst = dagArray[(nu.getDay()+1)];
    var dag = nu.getDate();
    var maandtekst = maandArray[(nu.getMonth()+1)];
    var jaar = nu.getYear();
    var jaar4 = ((jaar < 1900) ? (jaar + 1900) : (jaar));

    var datumweergave = dagtekst + " " + dag + " " + maandtekst + " " + jaar4;

    var uren = nu.getHours();
    var uren2 = ((uren < 10) ? "0" : "") + uren;
    var minuten = nu.getMinutes();
    var minuten2 = ((minuten < 10) ? ":0" : ":") + minuten;
    var seconden = nu.getSeconds();
    var seconden2 = ((seconden < 10) ? ":0" : ":") + seconden;

    var tijdweergave = uren2 + minuten2 + seconden2

    if (nu.getHours() >= 18)
    var welkom = ("Good Evening, ");
    else if (nu.getHours() >= 12)
    var welkom = ("Good afternoon, ");
    else if (nu.getHours() >= 6)
    var welkom = ("Good Morning, ");
    else
    var welkom = ("Good Night, ");

    var bericht = welkom + "it's now " + datumweergave + " @ " + tijdweergave + " h";

    document.write(bericht);
    //-->

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    This may help. You probably just want it to change the time every second right? As the date will still be the same.

    Timing Events

    Basscyst

  • #3
    New Coder
    Join Date
    Oct 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if the time is 23:59:59 then i should update the date to if this is possible!

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Here is some code. Hope it helps.

    <html>
    <head>
    <script language="javascript">
    function getTime(){
    var when=new Date();
    var month=when.getMonth() + 1;
    var day=when.getDate();
    var year=when.getYear();
    var hour=when.getHours();
    var minutes=when.getMinutes();
    var seconds=when.getSeconds();


    //Fix Time So >10 has a 0

    if (seconds<10){
    seconds="0" + seconds
    }
    if (minutes<10){
    minutes="0" + minutes
    }

    time=(month + "-" + day + "-" + year + " " + hour + ":" + minutes + ":" + seconds);
    }


    function writeTime()
    {
    getTime();
    document.getElementById('timespot').innerHTML=time;
    timer=setTimeout("writeTime()",1000);
    }



    </script>
    </head>
    <body onload="writeTime()">
    <div id="timespot"></div>
    </html>

    Basscyst
    Last edited by Basscyst; 10-21-2003 at 01:05 AM.

  • #5
    New Coder
    Join Date
    Oct 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thancks

    i changed it and still something not right there

    it displays Good Night, it's now undefined21-undefined-2003 02:44:05

    SCRIPT
    ----------
    function initArray() {
    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++)
    this[i+1] = initArray.arguments[i];
    }

    function getTime(){
    var dagArray = new initArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var maandArray = new initArray("January","February","March","April","May","June","July","August","September","October","N ovember","December");

    var nu=new Date();
    var month=nu.getMonth();
    var maandtekst=dagArray[(nu.getMonth()+1)];
    var day=nu.getDate();
    var dagtekst=dagArray[(nu.getDate()+1)];
    var year=nu.getYear();
    var hour=nu.getHours();
    var minutes=nu.getMinutes();
    var seconds=nu.getSeconds();


    //Fix Time So >10 has a 0
    if (hour<10){
    hour="0" + hour
    }
    if (seconds<10){
    seconds="0" + seconds
    }
    if (minutes<10){
    minutes="0" + minutes
    }

    if (nu.getHours() >= 18)
    var welkom = ("Good Evening, ");
    else if (nu.getHours() >= 12)
    var welkom = ("Good afternoon, ");
    else if (nu.getHours() >= 6)
    var welkom = ("Good Morning, ");
    else
    var welkom = ("Good Night, ");

    time=(welkom + "it's now " + dagtekst + day + "-" + maandtekst + "-" + year + " " + hour + ":" + minutes + ":" + seconds);

    }

    function writeTime()
    {
    getTime();
    document.getElementById('timespot').innerHTML=time;
    timer=setTimeout("writeTime()",1000);
    }
    Last edited by cavalera; 10-21-2003 at 02:02 AM.

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Fix these two and it will work.

    var nu=new Date();
    var month=nu.getMonth();
    var maandtekst=maandArray[(nu.getMonth()+1)];
    var day=nu.getDate();
    var dagtekst=dagArray[(nu.getDay()+1)];
    var year=nu.getYear();
    var hour=nu.getHours();
    var minutes=nu.getMinutes();
    var seconds=nu.getSeconds();

    ....Willy

  • #7
    New Coder
    Join Date
    Oct 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thancks a lot man
    now its working fine


  •  

    Posting Permissions

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