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>
需要进一步说明?

如果此页面上的说明未能涵盖您的所有问题,欢迎与其他 AMP 用户取得联系,讨论您的具体用例。

前往 Stack Overflow
一项无法解释的功能?

AMP 项目强烈鼓励您参与并做出贡献!我们希望您能成为我们开放源代码社区的持续参与者,但我们也欢迎您对所热衷问题做出一次性贡献。

编辑 GitHub 上的示例