AMP
  • websites

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>
Need further explanation?

If the explanations on this page don't cover all of your questions feel free to reach out to other AMP users to discuss your exact use case.

Go to Stack Overflow
An unexplained feature?

The AMP project strongly encourages your participation and contributions! We hope you'll become an ongoing participant in our open source community but we also welcome one-off contributions for the issues you're particularly passionate about.

Edit sample on GitHub