Funci贸n para mostrar fecha actual

Alberto
29 de Octubre del 2003
Hola. Soy nuevo y me gustar铆a saber c贸mo a帽adir un applett (o JavaScript ????, no s茅....) que muestre la fecha actual una vez incrustado en el c贸digo de la p谩gina. A ser posible en catal谩n.

Agradecer铆a cualquier explicaci贸n.
Muchas gracias!

mfercor
29 de Octubre del 2003
Bueno, te mando algo completito de fecha y hora local que podras personalizar. En el <head> de tu codigo inserta esto:

<script>
function StartWebDateTime()
{
CalculateDateTime()
window.setInterval('CalculateDateTime()', 1000)
}

function CalculateDateTime()
{
var WeekDays = new Array('Domingo', 'Lunes', 'Martes', 'Mi茅rcoles', 'Jueves', 'Viernes', 'S谩bado')
var Months = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre')
var PrintDate = new Date()
var WeekDay = PrintDate.getDay()
var Day = PrintDate.getDate()
var Month = PrintDate.getMonth()
var Year = PrintDate.getYear()

if (Year < 1000)
{
Year = 1900 + Year
}

PrintDate = (WeekDays[WeekDay] + ', ' + Day + ' de ' + Months[Month] + ' de ' + Year)

var PrintClock = new Date()
var Hour = PrintClock.getHours()
var Minutes = PrintClock.getMinutes()

if (Hour < 10)
{
Hour = '0' + Hour
}

if (Minutes < 10)
{
Minutes = '0' + Minutes
}

PrintClock1 = Hour + ':' + Minutes + ' h'
PrintClock2 = Hour + ';' + Minutes + ' h'

var WebDateTime

if (Browser.ie6 || Browser.ns6 || Browser.ns7)
{
WebDateTime = eval(document.getElementById('WebDateTime'))
}
else if (Browser.ie4 || Browser.ie5 || Browser.op5 || Browser.op6 || Browser.op7)
{
WebDateTime = eval(document.all.WebDateTime)
}
else if (Browser.ns4)
{
WebDateTime = eval(document.layers.WebDateTime)
}

var PrintDateTime = ';'

if (WebDateTime)
{
if (WebDateTime.innerHTML.indexOf(';') > -1)
{
PrintDateTime = '<span class="DateTime"><span class="DateTimeSeparators">[</span> ' + PrintDate +
'<span class="DateTimeSeparators"> | </span>' + PrintClock1 + ' ' +
'<span class="DateTimeSeparators">]</span> </span>'
}
else
{
PrintDateTime = '<span class="DateTime"><span class="DateTimeSeparators">[</span> ' + PrintDate +
'<span class="DateTimeSeparators"> | </span>' + PrintClock2 + ' ' +
'<span class="DateTimeSeparators">]</span> </span>'
}

WebDateTime.innerHTML = PrintDateTime
}
}

StartWebDateTime
</script>

Y en el <body>, donde quieras que aparezca la fecha y hora esto otro:

<script>
document.write('<div id="WebDateTime">?</div>')
</script>

Si tienes dudas mandame un mail ;)

mfercor
29 de Octubre del 2003
function CheckBrowser()
{
this.javascript = (window && navigator && document) ? 1 : 0
this.frames = (window.frames) ? 1 : 0
this.cookies = (navigator.cookieEnabled) ? 1 : 0

this.agent = navigator.userAgent.toLowerCase()
this.dom = (document.getElementById) ? 1 : 0

this.ns = (this.agent.indexOf('netscape') > -1) ? 1 : 0
this.op = (this.agent.indexOf('opera') > -1) ? 1 : 0
this.ie = (this.agent.indexOf('msie') > -1 && !this.op) ? 1 : 0

if (this.ns)
{
this.ns4 = (!this.dom && document.layers) ? 1 : 0
this.ns6 = (this.agent.indexOf('netscape 6') > -1 || this.agent.indexOf('netscape/6') > -1) ? 1 : 0
this.ns7 = (this.dom && !this.ns6) ? 1 : 0
}
else if (this.op)
{
this.op5 = (this.agent.indexOf('opera 5') > -1 || this.agent.indexOf('opera/5') > -1) ? 1 : 0
this.op6 = (this.agent.indexOf('opera 6') > -1 || this.agent.indexOf('opera/6') > -1) ? 1 : 0
this.op7 = (this.dom && !this.op5 && !this.op6) ? 1 : 0
}
else if (this.ie)
{
this.ie4 = (!this.dom && document.all) ? 1 : 0
this.ie5 = (this.agent.indexOf('msie 5') > -1 || this.agent.indexOf('msie 5.5') > -1) ? 1 : 0
this.ie6 = (this.dom && !this.ie5) ? 1 : 0
}

this.known = (this.ns4 || this.ns6 || this.ns7 || this.op5 || this.op6 || this.op7 || this.ie4 || this.ie5 || this.ie6)

return this
}

var Browser = new CheckBrowser()

se me olvidaba mandarte el chequeo del navegador, tienes que ponerlo en el head, antes de todo el codigo anterior ;)