Untitled
unknown
plain_text
a year ago
886 B
14
Indexable
function timeAgoInTurkish(date) {
const now = new Date()
const diffMs = now - date
const diffSec = Math.floor(diffMs / 1000)
const diffMin = Math.floor(diffSec / 60)
const diffHours = Math.floor(diffMin / 60)
const diffDays = Math.floor(diffHours / 24)
const diffMonths = Math.floor(diffDays / 30)
const diffYears = Math.floor(diffMonths / 12)
if (diffSec < 60) {
return 'az önce'
} else if (diffMin < 60) {
return `${diffMin} dk önce`
} else if (diffHours < 24) {
return `${diffHours} saat önce`
} else if (diffDays < 30) {
return `${diffDays} gün önce`
} else if (diffMonths < 12) {
return `${diffMonths} ay önce`
} else {
return `${diffYears} yıl önce`
}
}
const tarih = new Date('2023-09-17T12:00:00')
console.log(timeAgoInTurkish(tarih))Editor is loading...
Leave a Comment