unix-to-ist
v1.0.8
Published
A simple TypeScript utility to convert any date or Unix timestamp to Indian Standard Time (IST).
Downloads
16
Maintainers
Readme
unix-to-ist
Convert any date, Unix timestamp, or date string to Indian Standard Time (IST) easily.
📦 Installation
npm install unix-to-ist🚀 Usage
⏱️ Unix timestamp in seconds (10 digits)
import { convertToISTDate } from 'unix-to-ist';
const ist = convertToISTDate(1748616676, 'datetime');
console.log(ist); // => '29/5/2025, 5:31:16 AM'⏱️ Unix timestamp in milliseconds (13 digits)
const ist = convertToISTDate(1748616676000, 'time');
console.log(ist); // => '5:31:16 AM'📅 Date string
const ist = convertToISTDate("2025-05-29T00:00:00Z", 'date');
console.log(ist); // => '29/5/2025'📆 JavaScript Date object
const ist = convertToISTDate(new Date(), 'datetime');
console.log(ist); // => current IST date and time🧠 Function Signature
convertToISTDate(
dateInput: Date | number | string,
format?: 'date' | 'time' | 'datetime'
): stringParameters
dateInput: ADate, Unix timestamp (in seconds or milliseconds), or ISO date string.format: Optional.'date'→ returns only the date (e.g.,29/5/2025)'time'→ returns only the time (e.g.,5:31:16 AM)'datetime'(default) → returns full date and time (e.g.,29 May 2025, 5:31:16 AM)
🌍 Timezone Info
- This package assumes the input is in UTC (standard for Unix timestamps and ISO strings).
- It then converts the date to IST (Indian Standard Time), which is UTC +05:30.
💻 Compatibility
- Supports TypeScript out of the box.
- Works in both Node.js and React environments.
📄 License
ISC
