1.0.1 • Published 5 months ago
dayjs-tz-format v1.0.1
dayjs-tz-format
A Day.js plugin that combines timezone conversion and formatting functionality.
Installation
npm install dayjs dayjs-tz-format
Usage
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import tzFormat from 'dayjs-tz-format';
// Load the required plugins
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(tzFormat);
// Basic usage with system timezone
dayjs().tzFormat('YYYY-MM-DD HH:mm:ss');
// With specific timezone
dayjs().tzFormat('YYYY-MM-DD HH:mm:ss', 'Asia/Shanghai');
// Chain with other dayjs methods
dayjs('2024-02-18T10:00:00Z').tzFormat(
'YYYY-MM-DD HH:mm:ss',
'America/New_York'
);
API
tzFormat(format , timezone)
format
: String - The format string (same as dayjs.format())timezone
: String (optional) - The timezone name (e.g., 'Asia/Tokyo', 'America/New_York')
If no timezone is specified, the system's default timezone will be used.
Dependencies
This plugin requires the following Day.js plugins:
utc
timezone
Make sure to load them before using this plugin.
License
MIT