【发布时间】:2016-10-25 01:37:07
【问题描述】:
我正在使用 MediaWiki 的 UTCLiveClock.js,我正在尝试将其配置为在 PST/PDT 中显示时间。我以为我解决了这个问题,但是当午夜 UTC 到达 (00:00:00) 时,它将我的时间输出更改为 0-7:00:00。我需要正确显示,以便当 UTC 00:00:00 - 07:00:00 发生时,我的时间显示看起来不会一团糟。我通过 mediawiki 使用的小工具可以在 https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js
找到是的,我是菜鸟。我没有任何正式的编程知识。我只是想为服务器存在于 PST/PDT 中并遇到此问题的游戏构建一个 wiki。谷歌搜索过去 3 个小时的关键字搜索让我无处可去。请帮忙。
*/
/*global mw, $, UTCLiveClockConfig:true */
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.notify']).then( function () {
var $target;
function showTime( $target ) {
var now = new Date();
var hh = now.getUTCHours();
var mm = now.getUTCMinutes();
var ss = now.getUTCSeconds();
var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
$target.text( time );
var ms = now.getUTCMilliseconds();
setTimeout( function () {
showTime( $target );
}, 1100 - ms );
}
function liveClock() {
mw.util.addCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
if ( !window.UTCLiveClockConfig ) {
UTCLiveClockConfig = {};
}
var portletId = UTCLiveClockConfig.portletId || 'p-personal';
var nextNode = UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
var node = mw.util.addPortletLink(
portletId,
mw.util.getUrl( null, { action: 'purge' } ),
'',
'utcdate',
null,
null,
nextNode
);
if ( !node ) {
return;
}
$( node ).on( 'click', function ( e ) {
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () {
location.reload();
}, function () {
mw.notify( 'Purge failed', { type: 'error' } );
} );
e.preventDefault();
} );
showTime( $( node ).find( 'a:first' ) );
}
$( liveClock );
} );
编辑:
我最初解决问题的方法是在小时部分加上 -7:
var hh = now.getUTCHours()-7;
【问题讨论】:
-
这个“小工具”应该有更好的链接。你从哪里得到它?
-
直接来自 Mediawiki mediawiki.org/wiki/Extension:Gadgets 我的问题是绝对没有关于如何编辑 .js 以使其适合另一个时区的教程。我什么都找不到。
标签: javascript mediawiki