...

View Full Version : update the current date



cavalera
10-20-2003, 11:54 PM
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","November","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);
//-->

Basscyst
10-21-2003, 12:07 AM
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 (http://hotwired.lycos.com/webmonkey/98/29/index2a_page2.html?tw=programming)

Basscyst

cavalera
10-21-2003, 12:08 AM
if the time is 23:59:59 then i should update the date to if this is possible!

Basscyst
10-21-2003, 01:02 AM
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

cavalera
10-21-2003, 01:21 AM
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","November","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);
}

Willy Duitt
10-21-2003, 02:25 AM
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

cavalera
10-21-2003, 02:32 AM
Thancks a lot man
now its working fine



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum