UNPKG

dayjs-tz-format

Version:

A Day.js plugin that combines timezone conversion and formatting

58 lines (38 loc) 1.16 kB
# dayjs-tz-format A Day.js plugin that combines timezone conversion and formatting functionality. ## Installation ```bash npm install dayjs dayjs-tz-format ``` ## Usage ```javascript 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