[WordPress] 外掛分享: Localize Time

首頁外掛目錄 › Localize Time
40+
安裝啟用
★★★☆☆
3.3/5 分(3 則評價)
4312 天前
最後更新
問題解決
WordPress 3.0.1+ v1.0.0 上架:2014-05-29

內容簡介

這個 WordPress 外掛加入了 [localize_time] 短代碼。這個短代碼允許作者輸入任何時區的日期和時間。短代碼顯示帶時區的原始時間,接著顯示符合使用者地區設置的相同時間,這對於宣布現場活動(例如線上直播活動)給分散在不同地區的觀眾非常有用。

需要顯示的日期和時間是輸入在短代碼的內容,即位於 [localize_time] 和 [/localize_time] 標籤之間。時間可以使用幾乎任何可識別為日期和時間的格式來指定。

短代碼可以使用以下選項:

tz - 短代碼的內容所在的時區。如果省略此選項,則預設為網站的時區。時區使用任何可被 PHP 的 DateTimeZone 辨識的格式來指定。在此處查看完整的時區文檔。
fmt - 指定如何顯示原始時間的格式字符串。如果省略,則預設為網站的日期格式,接著是網站的時間格式,最後是時區。如果要精確輸出原始時間(帶時區),請指定 fmt="orig"。或者,您可以輸入使用 WordPress 通用設置選項上使用的相同代碼的格式字符串。在此處查看有關日期/時間格式字符串的完整文檔。
before_local - 本地時間之前的字符串。預設為 ‘ (
after_local - 本地時間之後的字符串。預設為 ‘)

範例

以下是使用短代碼的範例。這些範例中,網站的時區設置為美國/紐約(EST-5EDT),而使用者的時區為美國/洛杉磯(PST-8PDT)。

當地時間與原始時間不在同一年與月份:
[localize_time]1/1/2014 1:00 am[/localize_time]
輸出:
January 1, 2014 1:00 am EST (12/31/2013, 10:00:00 PM PST)

指定一個與網站時區不同的時區:
[localize_time tz=”Europe/Paris” ]July 14, 2014 19:00[/localize_time]
輸出:
July 14, 2014 7:00 pm CEST (7/14/2014, 10:00:00 AM PDT)

指定原始時間的格式:
[localize_time fmt=”m/d/Y g:i A T”]June 14, 2014 6:30 AM[/localize_time]
輸出:
06/14/2014 6:30 AM EDT (6/14/2014, 3:30:00 AM PDT)

指定一個與使用者相同時區的時間:
[localize_time tz=”PST”]3pm Nov. 1, 2014[/localize_time]
輸出:
November 1, 2014 3:00 pm PDT

注意:本地時間的顯示因時區和瀏覽器而異。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Localize Time」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This WordPress plugin adds the [localize_time] shortcode. The shortcode allows an author
to enter a date and time in any timezone. The shortcode displays the original time with
timezone, followed by the same time in the user’s timezone, formatted correctly for the
user’s locale. This is useful for announcing live events, e.g. a live online streaming
event, to widely dispersed audiences.
The date and time to be displayed are entered as the shortcode’s content, i.e. between the
[localize_time] and [/localize_time] tags. The time can be specified in almost
any format that’s recognizable as a date and time.
The shortcode takes the following options:

tz – the timezone the shortcode’s content is in. If this option is omitted, it defaults
to the site’s timezone. Timezones are specified in any format recognized by
PHP’s DateTimeZone.
fmt – a format string specifying how the original time should be displayed. If omitted,
it defaults to the site’s date format followed by the site’s time format followed by the
timezone. To output the original time exactly as entered (with the timezone), specify
fmt="orig". Or you can enter a format string using the same codes that are used on
WordPress’s General Settings tab. See
full documentation on date / time format strings here.
before_local – the string to precede the local time. Defaults to ‘ (‘
after_local – the string to follow the local time. Defaults to ‘)’

Examples
Below are examples of using the shortcode. For these examples, the site’s timezone is set to America/New_York (EST-5EDT) and the user is in the America/Los_Angeles (PST-8PDT) timezone.

Local time is in a different year and month from original time:
[localize_time]1/1/2014 1:00 am[/localize_time]
outputs:
January 1, 2014 1:00 am EST (12/31/2013, 10:00:00 PM PST)

Specify a time in timezone different from the site’s:
[localize_time tz=”Europe/Paris” ]July 14, 2014 19:00[/localize_time]
outputs:
July 14, 2014 7:00 pm CEST (7/14/2014, 10:00:00 AM PDT)

Specify a format for the original time:
[localize_time fmt=”m/d/Y g:i A T”]June 14, 2014 6:30 AM[/localize_time]
outputs:
06/14/2014 6:30 AM EDT (6/14/2014, 3:30:00 AM PDT)

Specify a time in the same timezone as the user:
[localize_time tz=”PST”]3pm Nov. 1, 2014[/localize_time]
outputs:
November 1, 2014 3:00 pm PDT

Note that the display of the local time varies by timezone and browser.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon