It does not work.
This will show not values:
Current Server Time:
London:
Frankfurt:
Toronto:
Chicago:
New York:
Tokyo:
It does not work.
This will show not values:
Current Server Time:
London:
Frankfurt:
Toronto:
Chicago:
New York:
Tokyo:
Hi
I take it your want to show the time in various cities around the world?? one way would be to use the getTimezoneOffset() command.. see this thread for a hint:
time thread
Sorry, I made a mistake.Simonf: We got past that bit.Code:if (typeof isHour!="undefined") return (num < 10 ? "0" + num : num);![]()
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Can you please tell me the whole code. It seems it is not correct:
I need for showing cities time as this (format 24h just time without date):
Please help.![]()
PHP Code:
Current Server Time:<span id="timecontainer"></span><br />
London:<span id="timecontainer2"></span><br />
Frankfurt:<span id="timecontainer3"></span><br />
Toronto: <span id="timecontainer4"></span><br />
Chicago: <span id="timecontainer5"></span><br />
New York: <span id="timecontainer6"></span><br />
Tokyo: <span id="timecontainer7"></span><br />
<script type="text/javascript">
new showLocalTime("timecontainer", "server-php", 0, "long") //GMT -5
new showLocalTime("timecontainer2", "server-php", 300, "long") //GMT +1
new showLocalTime("timecontainer3", "server-php", 420, "long") //GMT +2
new showLocalTime("timecontainer4", "server-php", 0, "long") //GMT -5
new showLocalTime("timecontainer5", "server-php", -60, "long") //GMT -6
new showLocalTime("timecontainer6", "server-php", 0, "long") //GMT -5
new showLocalTime("timecontainer7", "server-php", 540, "long") //GMT +9
</script>
The third parameter is the offset in minutes, I believe. So GMT +1 should be (5 + 1) * 60 == 360; GMT +9 should be (5 + 9) * 60 = 545.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Thanks for time. Please help me how to do correct above code for format 24 h.
So, e.g. 19:45 (Hour:Minutes)
If you correct the offsets, that code should be fine.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Do you mean code:Originally Posted by Twey
changed to:function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>12)? num-12 : num
return (hour==0)? 12 : hour
}
this will not work. Can you please give correct code for this?if (typeof isHour!="undefined")
return (num < 10 ? "0" + num : num);
No,changed toCode:if (typeof isHour!="undefined"){ //if this is the hour field var hour=(num>12)? num-12 : num return (hour==0)? 12 : hour }andCode:if (typeof isHour!="undefined") return (num < 10 ? "0" + num : num);toCode:this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"Code:this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes);
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
I do not know but it does not work.
I post whole code. Please give me whole code for time format 24hours
I'm confused.
PHP Code:<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
/***********************************************
* Local Time script- © Dynamic Drive ([url]http://www.dynamicdrive.com[/url])
* This notice MUST stay intact for legal use
* Visit [url]http://www.dynamicdrive.com/[/url] for this script and 100s more.
***********************************************/
var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]
function showLocalTime(container, servermode, offsetMinutes, displayversion){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.displayversion=displayversion
var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
this.localtime=this.serverdate=new Date(servertimestring)
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
this.updateTime()
this.updateContainer()
}
showLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setSeconds(this.localtime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}
showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
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);
}
setTimeout(function(){thisobj.updateContainer()}, 60000) //update container every second
}
function formatField(num, isHour){
if (typeof isHour!="undefined")
return (num < 10 ? "0" + num : num);
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}
</script>
Current Server Time:<span id="timecontainer"></span><br />
London:<span id="timecontainer2"></span><br />
Frankfurt:<span id="timecontainer3"></span><br />
Toronto: <span id="timecontainer4"></span><br />
Chicago: <span id="timecontainer5"></span><br />
New York: <span id="timecontainer6"></span><br />
<script type="text/javascript">
new showLocalTime("timecontainer", "server-php", 0, "long") //GMT -5
new showLocalTime("timecontainer2", "server-php", 300, "long") //GMT +1
new showLocalTime("timecontainer3", "server-php", 420, "long") //GMT +2
new showLocalTime("timecontainer4", "server-php", 0, "long") //GMT -5
new showLocalTime("timecontainer5", "server-php", -60, "long") //GMT -6
new showLocalTime("timecontainer6", "server-php", 0, "long") //GMT -5
</script>
Bookmarks