amp-timeago

Edit on Github
Open in Playground

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

Example

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

Example

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

Example

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

Example

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>