Svelte Time screenshot

Svelte Time

Author Avatar Theme by Metonym
Updated: 5 Apr 2025
149 Stars

Svelte component and action to format a timestamp using day.js

Categories

Overview

The svelte-time npm package is a utility that allows developers to format timestamps using the day.js library. It provides both a declarative Svelte component and an action for easily formatting timestamps in a Svelte application. This package is useful for displaying timestamps in a human-readable and customizable format.

Features

  • Svelte Component: Provides a declarative Svelte component for formatting timestamps using day.js.
  • Svelte Action: Offers an action that can be used to format a timestamp in a raw HTML element.
  • Flexible Timestamp Formats: Supports a variety of day.js values for the timestamp prop, including strings, numbers, Dates, and Dayjs objects.
  • Relative Time: Allows for displaying timestamps as human-readable relative time (e.g., “4 days ago”).
  • Live Updates: Provides an option for live updating relative timestamps, with a default refresh interval of 60 seconds.
  • Customizable Format: Allows developers to customize the format of the formatted timestamp using the format prop.
  • Custom Locale: Supports loading a custom locale and setting it as the default locale using the dayjs.locale API.

Installation

To install the svelte-time npm package, you can use the following command:

npm install svelte-time

Note: If you are a pnpm user, you will need to install dayjs separately in addition to svelte-time.

Summary

The svelte-time npm package provides a convenient way to format timestamps in a Svelte application using the day.js library. It offers a declarative Svelte component as well as an action for easily formatting timestamps. The package supports various timestamp formats, including relative time, and allows for live updating of timestamps. With customizable formatting options and support for custom locales, svelte-time is a powerful utility for displaying timestamps in a user-friendly and customizable manner.