timezone-lib
v1.0.4
Published
timezone library give you almost all county or region date and time.
Downloads
8
Maintainers
Readme
timezone-lib
library give you almost all county or region date and time, please check below for more.
✔ How to Install
using npm | yarn | pnpm command, you can install
timezone-lib
library.
npm install timezone-lib
yarn add timezone-lib
pnpm add timezone-lib
💢 How to Import
# using ES6+ (module-js approach)
import { TimeZone } from "timezone-lib"
or
# using ES5 (common-js approach)
const { TimeZone } = require("timezone-lib")
✨ A full-featured timezone aware date and time, or formatter for JavaScript.
timezone-lib
is a library in pure JavaScript with no dependencies that provides timezone aware date and time formatting or more.timezone formats dates with a full implementation of formats, by default all are set indian timezone.
timezone-lib offer fully secure and strict type safety.
😎 Examples
import { TimeZone } from 'timezone-lib';
const timezone = new TimeZone();
All Timezones List
const allTimezones = timezone.allTimezones();
console.log(allTimezones);
Output: [
'Asia/Calcutta',
'America/New_York',
...
]
Current Date And Time By TimeZone
const dateTimeInfo = timezone.currentDateAndTimeByTimeZone('Asia/Calcutta');
console.log(dateTimeInfo);
Output: {
date_and_time: '23/12/2023, 03:30:00 PM',
date: '23/12/2023',
time: '03:30:00 PM'
}
Current Date And Time Of All TimeZone
const allDateTimeInfo = timezone.currentDateAndTimeOfAllTimeZone();
console.log(allDateTimeInfo);
Output: {
'Asia/Calcutta': {
date_and_time: '12/23/2023, 10:30:00 AM',
date: '12/23/2023',
time: '10:30:00 AM' },
...
}
Separated Current Date And Time By TimeZone
const dateTimeInfo = timezone.separatedCurrentDateAndTimeByTimeZone('Asia/Calcutta');
console.log(dateTimeInfo);
Output: {
date_and_time: '12/23/2023, 10:30:00 AM',
date: '12/23/2023',
time: '10:30:00 AM'
}
Separated Current Date And Time Of All TimeZone
const allDateTimeInfo = timezone.separatedCurrentDateAndTimeOfAllTimeZone();
console.log(allDateTimeInfo);
Output: {
'Asia/Calcutta': {
date_and_time: '12/23/2023, 10:30:00 AM',
date: '12/23/2023',
time: '10:30:00 AM' },
...
}
Time Since
const elapsed = timezone.timeSince(new Date('2023-01-01T00:00:00'));
console.log(elapsed);
Output: 'about 11 months';
Get Expiration Date
const expirationInfo = timezone.getExpirationDate(1672531199000);
console.log(expirationInfo);
Output: 'about 1 day';
Format Date And Time
const formattedDateTime = timezone.formatDateAndTime(new Date(), true);
console.log(formattedDateTime);
Output: {
date: '2023-12-23',
time: '15:30:00'
}
Date Format
const formattedDate = timezone.dateFormat(new Date(), 'medium', 'fr-FR');
console.log(formattedDate);
Output: '23 déc. 2023';
Get Date And Time in GMT ISO UTC
const gmtIsoUtcInfo = timezone.getDateAndTimeInGmtIsoUtc(new Date());
console.log(gmtIsoUtcInfo);
Output: {
GMT: 'Sat, 23 Dec 2023 15:30:00 GMT',
ISO: '2023-12-23T15:30:00.000Z',
UTC: '2023-12-23 15:30:00 UTC'
}
☯ License
MIT License