#BlackLivesMatter
Do you build things with AMP? Fill out the new AMP Developer Survey!
AMP
  • email

amp-timeago

Introduction

The amp-timeago provides fuzzy timestamps by formatting dates as "X time ago"

Setup

Import the amp-timeago component

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

Basic usage

A simple example showing how long it has been since 14 March, 2017

Tuesday 14 March 2017 00.37
<amp-timeago class="m1"
  width="160"
  height="20"
  datetime="2017-03-14T00:37:33.809Z">Tuesday 14 March 2017 00.37</amp-timeago>

Different locale

The locale attribute allows you to get an output in a different language. By default the locale is set to en

Tuesday 14 March 2017 00.37
<amp-timeago class="m1"
  width="160"
  height="20"
  datetime="2017-03-14T00:37:33.809Z"
  locale="ml">Tuesday 14 March 2017 00.37</amp-timeago>

Dates in the future

The component supports dates in the future as well

Monday 14 March 2050 00.37
<amp-timeago class="m1"
  width="160"
  height="20"
  datetime="2050-03-14T00:37:33.809Z">Monday 14 March 2050 00.37</amp-timeago>

Cutoff time

Cutoff times are useful when it doesn't make sense to display "X time ago" after a threshold. Specify cutoff in seconds

Tuesday 14 March 2017 00.37
<amp-timeago class="m1"
  width="160"
  height="20"
  datetime="2017-03-14T00:37:33.809Z"
  cutoff="600">Tuesday 14 March 2017 00.37</amp-timeago>
Perlu penjelasan lebih lanjut?

Jika penjelasan pada halaman ini tidak menjawab semua pertanyaan Anda, silakan hubungi pengguna AMP lainnya untuk mendiskusikan contoh penggunaan Anda yang spesifik.

Kunjungi Stack Overflow
Fitur yang tidak dijelaskan?

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.

Edit sampel di GitHub