Do you build things with AMP? Fill out the AMP Developer Survey!
AMP

Important: this documentation is not applicable to your currently selected format ads!

amp-timeago

Description

Provides fuzzy timestamps by formatting dates as time ago (for example, 3 hours ago).

Required Scripts

<script async custom-element="amp-timeago" src="https://cdn.ampproject.org/v0/amp-timeago-0.1.js"></script>

Supported Layouts

Usage

Use the amp-timago component to count up to, or away from, a specified date and time.

The component replaces the text node with a fuzzy timestamp, such as in 30 years or 3 hours ago.

Example:

Saturday 11 April 2017 00.37
<amp-timeago
  layout="fixed"
  width="160"
  height="20"
  datetime="2017-04-11T00:37:33.809Z"
  locale="en"
>
  Saturday 11 April 2017 00.37
</amp-timeago>
Buka cuplikan ini di playground

The amp-timeago component requires a placeholder in the text node. The calculated timestamp replaces the placeholder once ready. Use the placeholder as a fallback to display to users if amp-timeago is unable to process the fuzzy timestamp.

Attributes

datetime

The required datetime attribute sets the date and time. The value must be an ISO datetime.

  • Express time in UTC (Coordinated Universal Time): 2017-03-10T01:00:00Z
  • Express in local time with a time zone offset: 2017-03-09T20:00:00-05:00

locale (optional)

The local default is en. Add the locale attribute and specify one of the following values to chance the local.

  • ar (Arabic)
  • be (Belarusian)
  • bg (Bulgarian)
  • ca (Catalan)
  • da (Danish)
  • de (German)
  • el (Greek)
  • en (English)
  • enShort (English - short)
  • es (Spanish)
  • eu (Basque)
  • fi (Finnish)
  • fr (French)
  • he (Hebrew)
  • hu (Hungarian)
  • inBG (Bangla)
  • inHI (Hindi)
  • inID (Malay)
  • it (Italian)
  • ja (Japanese)
  • ko (Korean)
  • ml (Malayalam)
  • nbNO (Norwegian Bokmål)
  • nl (Dutch)
  • nnNO (Norwegian Nynorsk)
  • pl (Polish)
  • ptBR (Portuguese)
  • ro (Romanian)
  • ru (Russian)
  • sv (Swedish)
  • ta (Tamil)
  • th (Thai)
  • tr (Turkish)
  • uk (Ukrainian)
  • vi (Vietnamese)
  • zhCN (Chinese)
  • zhTW (Taiwanese)

cutoff

Add the cutoff attribute to display the date specified in the datatime attribute after passing the specified date in seconds.

Common attributes

The AMP provided set of common attributes is available to <amp-timeago>.

Validation

See amp-timeago rules in the AMP validator specification.

Perlu bantuan lainnya?

Anda telah membaca dokumen ini belasan kali, tetapi belum semua pertanyaan Anda terjawab? Mungkin orang lain merasakan hal yang sama. Berinteraksilah dengan mereka di Stack Overflow.

Kunjungi Stack Overflow
Menemukan bug atau ada fitur yang kurang?

Proyek AMP sangat menganjurkan partisipasi dan kontribusi Anda! Kami berharap Anda akan terus ambil bagian dalam komunitas sumber terbuka kami, tetapi kami juga menerima kontribusi satu kali untuk topik tertentu yang Anda minati.

Kunjungi GitHub