تصف هذه المقالة طريقة عرض وقت بكين في الوقت الفعلي بواسطة JavaScript. شاركه للرجوع إليه. التفاصيل كما يلي:
يتم عرض وقت بكين في الوقت الفعلي في هذه الصفحة. يمكن أيضًا استخدام تغيير المنطقة الزمنية لعرض وقت العالم. الرمز كما يلي:
انسخ الرمز كما يلي: <script type = "text/javaScript">
date.prototype.strftime = function (format) {
var o = {
"M+": this.getmonth ()+1 ، // month
"D+": this.getDate () ، // day
"H+": this.gethours () ، // ساعة
"M+": this.getMinutes () ، // دقيقة
"S+": this.getSeconds () ، // الثانية
"Q+": Math.Floor ((this.getMonth ()+3)/3) ، // Quarter
"S": this.getmilliseconds () // millisecond
}
if (/(y+)/. test (format)) {
Format = format.replace (regexp. $ 1 ، (this.getlyear ()+""). Senttr (4 - regexp. $ 1.Length)) ؛
}
لـ (var k in o) {
if (new regexp ("(" + k + ")"). اختبار (تنسيق)) {
Format = format.replace (regexp. $ 1 ، regexp. $ 1.Length == 1؟ o [k]: ("00"+ o [k]).
}
}
تنسيق العودة
}
وظيفة utctolocaltimestring (D ، تنسيق) {
var timeOffSetInhours = (Date Date (). getTimeZoneOffset ()/60) + -10 ؛
D.Sethours (d.gethours () + timeOffSetInhours) ؛
إرجاع d.strftime (تنسيق) ؛
}
</script>
<script>
setInterval (function () {var time = utctolocaltimestring (date date () ، 'Yyyy/mm/dd hh: mm: ss') ؛ document.getElementById ("bjtime"). innerhtml = time ؛} ، 1000) ؛
</script>
<span id = "bjtime"> </span>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.