Giter VIP home page Giter VIP logo

timeago.js's Introduction

timeAgo.js

timeAgo.js is a nano library used to format datetime in 5 different languages. eg: '3 days ago'.

Browser Version Support
Chrome Latest Yes
Firefox Latest Yes
Safari Latest Yes
Edge Latest Yes
Opera Latest Yes

Demo

English (en)

just now
12 seconds ago
2 minutes age
2 hours ago
3 days ago
3 month ago
2 years ago

German (de)

Jetzt
Vor 12 Sekunden
Vor 12 Minute
Vor 2 Stunde
Vor 3 Tage
Vor 3 Monate
Vor 2 Jahre

Arabic (ar)

الآن
منذ 12 ثانية
منذ 12 دقيقة
منذ 2 ساعة
منذ 3 يوم
منذ 3 شهر
منذ 2 سنة

Kurdish Kurmanji (ku)

nuha
12 çirke berê
12 deqîqe berê
2 saet berêrê
3 roj berê
3 meh berê
2 sal berê

Kurdish Sorani (ckb)

ئێستا
12 چرکە پێش ئێستا
12 خولەك پێش ئێستا
2 کاتژمێر پێش ئێستا
3 ڕۆژ پێش ئێستا
3 مانگ پێش ئێستا
2 ساڵ پێش ئێستا

Usage

Install/Import <script> before </head>

<script src="./timeAgo.js"></script>
<script src="https://cdn.jsdelivr.net/gh/Rawandev-top/timeAgo.js@main/timeAgo.js"></script>

Then add <script> before </body>

<script>
  // Load timeAgo.js
  const timeago = new TimeAgo("en");

  // Update timestamps
  document.querySelectorAll(".timestamp").forEach((element) => {
    const timestamp = new Date(element.getAttribute("date-time"));
    element.innerText = timeago.format(timestamp);
  });
</script>

Change TimeAgo("en") to the language that you want

  • language codes:
    • en for English
    • de for German
    • ar for Arabic
    • ckb for Kurdish Sorani
    • ku for Kurdish Kurmaji

How to use?

<div class="timestamp" date-time="2023-11-18 23:03:12"></div> /* 2 minutes ago */
  • for example day/month/year hour:minute:second or year-month-day hour:minute:second
<div class="timestamp" date-time="11/18/2023 08:44:12 AM"></div> /* 2 minutes ago */
<div class="timestamp" date-time="11/18/2023 08:44:12 PM"></div> /* منذ 12 ثانية */
<div class="timestamp" date-time="2023-11-18 21:03:12 AM"></div> /* 2 کاتژمێر پێش ئێستا */
<div class="timestamp" date-time="2023-11-18 21:03:12 PM"></div> /* Vor 3 Monate */
<div class="timestamp" date-time="11/18/2023 08:44:12"></div> /* 2 sal berê */
<div class="timestamp" date-time="11/18/2023 20:44:12"></div> /* Vor 2 Stunde */
<div class="timestamp" date-time="2023-11-18 21:03:12"></div> /* just now */

timeago.js's People

Contributors

itsr4wand avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.