PDA

View Full Version : Change display of date for Local Time Script



Foundas
10-19-2011, 02:05 PM
1) Script Title: Local Time script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex6/localtime.htm

3) Describe problem:
Hello,

the script is great, many thanks. I am using displayversion=="short" top show the date but i want to change i.e. 19 October 2011 to 19/10/2011

im using this:



showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="short")
this.container.innerHTML=this.localtime.toLocaleString()
else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=""
var dayofweek=weekdaystxt[this.localtime.getDay()]
//this.container.innerHTML=formatField(hour)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
this.container.innerHTML=formatField(hour)+":"+formatField(minutes)
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

how can i do this?

thanks in advance

jscheuer1
10-19-2011, 02:45 PM
How about we create our own displayversion and call it "min":


showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else if(this.displayversion=="min"){
this.container.innerHTML=this.localtime.getDate() + '/' + (this.localtime.getMonth() + 1) + '/' + this.localtime.getFullYear();
}else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
var dayofweek=weekdaystxt[this.localtime.getDay()]
this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

Then you can do like:


<script type="text/javascript">
new showLocalTime("timecontainer", "server-ssi", 0, "min")
</script>

If you still want the 9:34:32 AM part:


showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else if(this.displayversion=="min"){
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
this.container.innerHTML = formatField(hour, 1 )+ ':' + formatField(minutes) + ':' + formatField(seconds) + ' ' +
ampm + ' ' + this.localtime.getDate() + '/' + (this.localtime.getMonth() + 1) + '/' + this.localtime.getFullYear();
}else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
var dayofweek=weekdaystxt[this.localtime.getDay()]
this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

Foundas
10-19-2011, 03:08 PM
Hi John,

many thanks for that....i am actually using your modification from another post, where i show the date in 24h and removed the seconds too...moved date in front of time and now i have 19/10/2011 18:00


thank you!!!!!

jscheuer1
10-19-2011, 04:26 PM
For anyone interested, that would be:


showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else if(this.displayversion=="min"){
var hour=this.localtime.getHours();
var minutes=this.localtime.getMinutes();
this.container.innerHTML = this.localtime.getDate() + '/' + (this.localtime.getMonth() + 1) + '/' +
this.localtime.getFullYear() + ' ' + formatField(hour)+ ':' + formatField(minutes);
}else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=12)? "PM" : "AM"
var dayofweek=weekdaystxt[this.localtime.getDay()]
this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}