
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
timezone-friendly
Advanced tools
A lightweight package that automatically converts and formats date and time string based on the user's time zone, with optional friendly formatting
TimeZoneFriendly is a lightweight, easy-to-use library for automatically converting and formatting date and time strings based on the user's time zone. It’s designed for both JavaScript and React, with features like customizable friendly text (e.g., "2 hours ago"), time zone conversions, and flexible date formats.
You can install the package via npm:
npm install timezone-friendly
Here’s a basic example of how to use TimeZoneFriendly in a React component:
import React from "react";
import TimeZoneFriendly from "timezone-friendly";
const App = () => {
const date = "2024-09-26T12:00:00Z"; // Example ISO date
// Example of converting a date to a user's local time zone and formatting it.
const formattedDate = TimeZoneFriendly(date, { friendly: true });
return (
<div>
<h1>TimeZoneFriendly Demo</h1>
<p>Friendly Date: {formattedDate}</p>
</div>
);
};
export default App;
| Prop | Type | Description |
|---|---|---|
friendly | boolean | Shows relative time like "2 hours ago" when true. Defaults to false. |
formatString | string | Custom date format string. Defaults to "yyyy-MM-dd HH:mm:ss". |
locale | string | Locale code for formatting (e.g., "en", "fr", "es"). Defaults to "en". |
targetTimeZone | string | Converts date to a specific time zone (e.g., "America/New_York"). |
inputFormat | string | Format for parsing custom date inputs (e.g., "dd/MM/yyyy"). |
customText | object | Object to override default text for "just now" and "soon". |
showDate | boolean | Controls whether the date is shown. Defaults to true. |
showTime | boolean | Controls whether the time is shown. Defaults to true. |
const friendlyTime = TimeZoneFriendly("2024-09-26T12:00:00Z", { friendly: true });
const customFormattedDate = TimeZoneFriendly("2024-09-26T12:00:00Z", {
friendly: false,
formatString: "dd/MM/yyyy"
});
const timeZoneConvertedDate = TimeZoneFriendly("2024-09-26T12:00:00Z", {
friendly: false,
targetTimeZone: "America/New_York"
});
const customText = TimeZoneFriendly(new Date(), {
friendly: true,
customText: { justNow: "just now", soon: "soon" }
});
const dateOnly = TimeZoneFriendly("2024-09-26T12:00:00Z", { friendly: false, showDate: true, showTime: false });
const timeOnly = TimeZoneFriendly("2024-09-26T12:00:00Z", { friendly: false, showDate: false, showTime: true });
The TimeZoneFriendly package is designed to be used in accessible applications, with keyboard and screen reader support in mind when rendering dates and times in a user-friendly format.
This project is licensed under the MIT License – see the LICENSE file for details.
FAQs
A lightweight package that automatically converts and formats date and time string based on the user's time zone, with optional friendly formatting
We found that timezone-friendly demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.