Fecha ligera de lectura humana & biblioteca de tiempo-timeago. js

Tiempo de ejecución: 30 minutos. Empezar

Autor: hustcc
Views Total: 2,105
Sitio oficial: Ir a la web
Actualizado: December 14, 2018
Licencia: MIT

Vista prévia

Fecha ligera de lectura humana & biblioteca de tiempo-timeago. js

Descripción

timeago. js es una versión ligera y pura de JavaScript del familiar jQuery timeago plugin que permite analizar y formatear fechas & veces usando lenguaje natural como ' hace 5 minutos '.

¿Cómo funciona?

Instale e importe el timeago. js en su proyecto Web.

npm install timeago.js
import timeago from 'timeago.js';
<script src="dist/timeago.min.js"></script>

Cree un nuevo objeto hace tiempo y formatee un tiempo de fecha especificado como sigue:

var timeago = timeago();
timeago.format('2016-09-12')

Formatee y represente la fecha & hora dentro de un contenedor específico.

<div class="demo" data-timeago="2016-09-12 00:20:00"></div>
timeago().render(document.querySelectorAll('.demo')');

Personalice las cadenas de salida.

var myDict = function(number, index) {


return [



['just now', 'a while'],



['%s seconds ago', 'in %s seconds'],



['1 minute ago', 'in 1 minute'],



['%s minutes ago', 'in %s minutes'],



['1 hour ago', 'in 1 hour'],



['%s hours ago', 'in %s hours'],



['1 day ago', 'in 1 day'],



['%s days ago', 'in %s days'],



['1 week ago', 'in 1 week'],



['%s weeks ago', 'in %s weeks'],



['1 month ago', 'in 1 month'],



['%s months ago', 'in %s months'],



['1 year ago', 'in 1 year'],



['%s years ago', 'in %s years']


][index];
};

var timeago = timeago();
timeago.register('myStrings', myDict);

timeago.format('2016-09-12', 'myStrings');

Registro de cambios

12/14/2018

  • v4.0.0-beta.2

05/27/2018

  • v4.0.0

06/21/2017

  • v3.0.2

Te puede interesar: