Convert Dates to Persian Time in React

PersianTime is a simple utility to convert any date or time to Iran’s local time with Persian date formatting. Whether you’re building an application for Iranian users or need to handle dates in the Persian calendar, this library has got you covered!


This content originally appeared on DEV Community and was authored by Joodi

PersianTime is a simple utility to convert any date or time to Iran's local time with Persian date formatting. Whether you're building an application for Iranian users or need to handle dates in the Persian calendar, this library has got you covered!

Image description

Features

  • Convert any given date or time into Iran's local time (UTC +3:30).
  • Persian date formatting for easy reading in Iranian format.
  • Easy-to-use function for quick integration into any JavaScript/TypeScript project.

Installation

You can easily install PersianTime using npm:

npm install persiantime

Or, if you're using Yarn:

yarn add persiantime

Usage

Once installed, you can import and use the PersianTime function to format any date or timestamp into Persian time.

Example:

import { PersianTime } from 'persiantime';

const persianFormattedTime = PersianTime(new Date('2025-01-20T11:05:20.451Z'));

console.log(persianFormattedTime);

In the example above, you can see that the date is converted to Persian format and Tehran local time is applied.

Handling Dates from APIs:

If you receive a date from an API in ISO format, you can use the following approach to convert it:

import { PersianTime } from 'persiantime';

const createdAt = PersianTime(new Date(document.created_at));
const updatedAt = PersianTime(new Date(document.updated_at));

console.log(createdAt);
console.log(updatedAt);

Why PersianTime?

Accurate Time Conversion: Automatically adjusts to Iran's time zone (UTC+3:30).
Easy Integration: Works with both JavaScript and TypeScript projects.
Simple and Lightweight: Focused solely on converting date and time with minimal dependencies.
Contributing
PersianTime is an open-source project and contributions are always welcome! Feel free to fork the repo, make improvements, and create pull requests. If you encounter any issues or have suggestions for new features, please open an issue on the GitHub repository.

Support

If you find this library helpful, please consider giving it a star on GitHub and leave a review on npm. Your support will encourage me to continue improving it and adding more features.

Links

đź”— PersianTime on npm
📦 PersianTime GitHub Repository

Thanks for using PersianTime! 🌟


This content originally appeared on DEV Community and was authored by Joodi


Print Share Comment Cite Upload Translate Updates
APA

Joodi | Sciencx (2025-01-27T12:46:03+00:00) Convert Dates to Persian Time in React. Retrieved from https://www.scien.cx/2025/01/27/convert-dates-to-persian-time-in-react/

MLA
" » Convert Dates to Persian Time in React." Joodi | Sciencx - Monday January 27, 2025, https://www.scien.cx/2025/01/27/convert-dates-to-persian-time-in-react/
HARVARD
Joodi | Sciencx Monday January 27, 2025 » Convert Dates to Persian Time in React., viewed ,<https://www.scien.cx/2025/01/27/convert-dates-to-persian-time-in-react/>
VANCOUVER
Joodi | Sciencx - » Convert Dates to Persian Time in React. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/27/convert-dates-to-persian-time-in-react/
CHICAGO
" » Convert Dates to Persian Time in React." Joodi | Sciencx - Accessed . https://www.scien.cx/2025/01/27/convert-dates-to-persian-time-in-react/
IEEE
" » Convert Dates to Persian Time in React." Joodi | Sciencx [Online]. Available: https://www.scien.cx/2025/01/27/convert-dates-to-persian-time-in-react/. [Accessed: ]
rf:citation
» Convert Dates to Persian Time in React | Joodi | Sciencx | https://www.scien.cx/2025/01/27/convert-dates-to-persian-time-in-react/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.