format-with-timezone
v1.0.7
Published
A utility to format date and time to different timezones with various formats.
Downloads
494
Readme
Format With Timezone
A simple utility to format date strings in specific time zones using the format-with-timezone package.
Installation
To install the package, run:
npm install format-with-timezone
#codepart
const formatDateWithTimezone = require('format-with-timezone');
// Example date string
const dateString = '2024-10-27T04:00:00Z';
// Format the date to a specified timezone and format
const fullDate = formatDateWithTimezone(dateString, 'Asia/Kolkata', 'full');
console.log(fullDate); // Output: "Sun, Oct 27, 2024, 09:30 AM"
const dateOnly = formatDateWithTimezone('2024-10-27T04:00:00Z', 'Asia/Kolkata', 'date-only');
console.log(dateOnly); // Output: "Sun, Oct 27, 2024"
const timeOnly = formatDateWithTimezone('2024-10-27T04:00:00Z', 'Asia/Kolkata', 'time-only');
console.log(timeOnly); // Output: "09:30 AM"
const longDate = formatDateWithTimezone('2024-10-27T04:00:00Z', 'Asia/Kolkata', 'long-date');
console.log(longDate); // Output: "Sunday, October 27, 2024"
const shortFormat = formatDateWithTimezone('2024-10-27T04:00:00Z', 'Asia/Kolkata', 'short');
console.log(shortFormat); // Output: "2024-10-27"
const monthDate = formatDateWithTimezone('2024-10-27T04:00:00Z', 'Asia/Kolkata', 'month-date');
console.log(monthDate); // Output: "Oct 27"
const separateDetails=formatDateWithTimezone('2024-10-28T15:30:00Z', 'Asia/Kolkata','month-year-date');
console.log(separateDetails); // Output: { month: 'Oct', year: 2024, date: '28' }