Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@date-fns/tz

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@date-fns/tz

date-fns timezone utils

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is @date-fns/tz?

@date-fns/tz is a timezone utility library that extends the capabilities of date-fns, allowing users to work with time zones in JavaScript. It provides functions to convert dates between time zones, format dates in specific time zones, and parse date strings with time zone information.

What are @date-fns/tz's main functionalities?

Convert Date to Time Zone

This feature allows you to convert a date from a specific time zone to UTC. The code sample demonstrates converting a date from the 'America/New_York' time zone to UTC.

const { zonedTimeToUtc } = require('@date-fns/tz');
const date = new Date('2023-10-10T10:00:00Z');
const timeZone = 'America/New_York';
const utcDate = zonedTimeToUtc(date, timeZone);
console.log(utcDate.toISOString());

Format Date in Time Zone

This feature allows you to format a date in a specific time zone. The code sample shows how to format a UTC date to the 'America/New_York' time zone.

const { format } = require('date-fns');
const { utcToZonedTime } = require('@date-fns/tz');
const date = new Date('2023-10-10T10:00:00Z');
const timeZone = 'America/New_York';
const zonedDate = utcToZonedTime(date, timeZone);
const formattedDate = format(zonedDate, 'yyyy-MM-dd HH:mm:ssXXX', { timeZone });
console.log(formattedDate);

Parse Date String with Time Zone

This feature allows you to parse a date string that includes time zone information and convert it to UTC. The code sample demonstrates parsing a date string with a time zone offset and converting it to UTC.

const { parseISO, format } = require('date-fns');
const { zonedTimeToUtc } = require('@date-fns/tz');
const dateString = '2023-10-10T10:00:00-04:00';
const timeZone = 'America/New_York';
const date = parseISO(dateString);
const utcDate = zonedTimeToUtc(date, timeZone);
console.log(format(utcDate, 'yyyy-MM-dd HH:mm:ssXXX'));

Other packages similar to @date-fns/tz

Keywords

FAQs

Package last updated on 31 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc