السلام عليكم ورحمة الله وبركاته
الوقت المحلى لكل دولة Local Time script
كود بالجافا سكربت يتيح لك عرض الوقت لأكثر من مكان فى ان واحد عن طريق التحديد المسبق بين الأماكن بالدقائق بالأضافة انه يدعم صفحات ال php , asp , shtml
Want to display the current local time of a specific place in the world? This DHTML script, with the help of either PHP, ASP, or SSI (server side includes), displays the current server time your site is hosted on, and in turn, the local time of anywhere on Earth. You can use it to show visitors your current local time, or the time in New York, Tokyo etc. Now, in order to use this script, the webpage you're adding it to must be either PHP (ie: .php), ASP, or SSI (ie: .shtml) enabled. More on this below.
As mentioned, this local time script uses the time of the server hosting your site as its reference point. To display the local time of Paris then, simply enter into the script the time differential between Paris and your server time (ie: +120 minutes), and Paris' Time is derived and shown. By using the server time instead of each visitor's computer clock as the reference point, this script is more reliable, since you only have to account for a single time being accurate in order for the script to be, and that is your server's time. Contrast that with a local time script that uses each visitor's PC clock for its calculations- if the visitor's time is incorrect, he/she will also get an incorrect local (ie: Paris) time.
Finally, this script can be called multiple times on the same page to display simultaneously the local times of different places.
التركيب :
ضع فى وسام الهيدر <head> ... </head> الكود التالى
كود PHP:
<script type="text/javascript">
/***********************************************
* Local Time script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ 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)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}
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
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}
</script>
لعرض الوقت الحالى لمنطقة واحدة استخدم الكود التالى
كود PHP:
Current Server Time:<span id="timecontainer"></span>
<script type="text/javascript">
new showLocalTime("timecontainer", "server-ssi", 0, "short")
</script>
مع الأخذ فى الأعتبار تلك المتغيرات :
timecontainer : هذا متغير يتم تزويدة بأرقام عن ظهور مناطق اخري مثل
timecontainer1 و
timecontainer2 ..........الخ
server-ssi : تحدد على حسب الصفحات التى توضع فيها الكود يمكنك تغير ssi ألى php او ASP
الرقم 0 : هذا عند اختلاف الوقت الحالى عن وقت السيرفر يتم الزيادة او النقصان
فمثلا ان كان الوقت زائد بساعتين مثلا يكون الرقم بدل 0 هو 120 او ان
كان الوقت متأخرا بساعه مثلا يكون بدل الرقم 0 هو -60
short or long : متغير short لظهور الوقت فقط اما المتغير long فهو لظهور اليوم بجانب الساعه
كود كاملا لمثال تعدد المناطق :
كود PHP:
Current Server Time:<span id="timecontainer"></span><br />
Current LA Time:<span id="timecontainer2"></span><br />
Current New York Time:<span id="timecontainer3"></span><br />
<script type="text/javascript">
new showLocalTime("timecontainer", "server-asp", 0, "short")
new showLocalTime("timecontainer2", "server-asp", -60, "short")
new showLocalTime("timecontainer3", "server-asp", 120, "short")
</script>
بالتوفيق بإذن الله