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>
Ti servono altre spiegazioni?

Se le spiegazioni riportate in questa pagina non rispondono a tutte le tue domande, non esitare a contattare altri utenti AMP per discutere il tuo caso d'uso specifico.

Vai a Stack Overflow
Ci sono funzioni non descritte?

Il progetto AMP invita tutti a partecipare e dare il proprio contributo! Ci auguriamo che tu possa partecipare regolarmente alla nostra community open source, ma saremo anche lieti di ricevere eventuali contributi una-tantum sulle questioni che ti interessano.

Modifica esempio in GitHub