A simple Svelte component to provide relative time in the n{unit} ago format.
Install the package:
npm i svelte-timeago
Import the package
<script>
import TimeAgo from 'svelte-timeago';
</script>
<TimeAgo date="2021-10-25 11:13:00" live/>
dateDefault: null
Date should be a valid Date object, a valid UNIX timestamp or a valid date string, preferably in ISO-8601 format.
liveDefault: false
Should the displayed time update every 1 second?
withSuffixDefault: true
Should the word ago be displayed after the time?
asPrefixDefault: true
Should the suffix be a prefix instead? i.e. Il y à n{unit}
suffixDefault: ago
The suffix used when withSuffix is set to true.
unitsDefault:
{
seconds:'s',
minutes:'m',
hours:'h',
days:'d',
months:'mo',
years:'y'
}
The units to be displayed. Can also be used to set your own locale. i.e. 秒、分、時間 etc.