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 |
just now
12 seconds ago
2 minutes age
2 hours ago
3 days ago
3 month ago
2 years ago
Jetzt
Vor 12 Sekunden
Vor 12 Minute
Vor 2 Stunde
Vor 3 Tage
Vor 3 Monate
Vor 2 Jahre
الآن
منذ 12 ثانية
منذ 12 دقيقة
منذ 2 ساعة
منذ 3 يوم
منذ 3 شهر
منذ 2 سنة
nuha
12 çirke berê
12 deqîqe berê
2 saet berêrê
3 roj berê
3 meh berê
2 sal berê
ئێستا
12 چرکە پێش ئێستا
12 خولەك پێش ئێستا
2 کاتژمێر پێش ئێستا
3 ڕۆژ پێش ئێستا
3 مانگ پێش ئێستا
2 ساڵ پێش ئێستا
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 Englishde
for Germanar
for Arabicckb
for Kurdish Soraniku
for Kurdish Kurmaji
<div class="timestamp" date-time="2023-11-18 23:03:12"></div> /* 2 minutes ago */
- for example
day/month/year hour:minute:second
oryear-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 */