How to use the date-fns-tz.format function in date-fns-tz

To help you get started, we’ve selected a few date-fns-tz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github derhuerst / parse-human-relative-time / example.js View on Github external
const {format} = require('date-fns-tz')
const parseWithLuxon = require('.')(DateTime)
const parseWithDateFns = require('./date-fns')(dateFns)

// Europe/Berlin switched to DST at 31st of March at 2am.
const withoutDST = '2019-03-31T01:59+01:00'
const timeZone = 'Europe/Berlin'
const rel = 'in 2 minutes'

const dt = DateTime.fromISO(withoutDST).setZone(timeZone)
const withDST1 = parseWithLuxon(rel, dt)
console.log(withDST1.toFormat('HH:mm ZZZZ'))
// 03:01 GMT+2

const withDST2 = parseWithDateFns(rel, new Date(withoutDST))
console.log(format(withDST2, 'HH:mm zz', {timeZone: 'Europe/Berlin'}))
// 03:01 GMT+2
github stone-payments / pos-mamba-sdk / packages / utils / date.js View on Github external
export function format(date, mask) {
  if (typeof date.getFullYear !== 'function') {
    throw new Error('Must pass a Date object to format it');
  }

  if (typeof mask !== 'string' || !mask.length) {
    throw new Error(
      "Invalid mask passed. Must be a string of these characters: 'dd', 'm', 'mm', 'yy', 'yyyy', 'h', 'hh', 'H', 'HH', 'M', 'MM', 's', 'ss'",
    );
  }
  return formatDate(date, mask);
}
github joelshepherd / tabliss / src / plugins / widgets / nba / api.ts View on Github external
function getEstString(date: Date) {
  const dateUTC = zonedTimeToUtc(
    startOfDay(date),
    Intl.DateTimeFormat().resolvedOptions().timeZone,
  );
  const dateEST = utcToZonedTime(dateUTC, 'EST');
  return format(dateEST, 'yyyyMMdd');
}

date-fns-tz

Time zone support for date-fns v3 with the Intl API

MIT
Latest version published 8 days ago

Package Health Score

85 / 100
Full package analysis