Parsing and formatting date strings using IANA time zones for date-fns.
npm install date-fns-timezoneProvides parsing and formatting date strings and time zone conversions supporting [IANA time zones], following the design of functions in [date-fns]. List of canonical time zone names is provided by [timezone-support].
- Synopsis
- Installation and Getting Started
- Usage Scenarios
- API Reference
- Contributing
- Release History
- License
``js
const { listTimeZones } = require('timezone-support')
const { parseFromTimeZone, formatToTimeZone } = require('date-fns-timezone')
// List canonical time zone names: [ 'Africa/Abidjan', ... ]
const timeZones = listTimeZones()
// Set the date to "2018-09-01T16:01:36.386Z"
const date = parseFromTimeZone('2018-09-01 18:01:36.386', { timeZone: 'Europe/Berlin' })
// Set the output to "1.9.2018 18:01:36.386 GMT+02:00 (CEST)"
const date = new Date('2018-09-01Z16:01:36.386Z')
const format = 'D.M.YYYY HH:mm:ss.SSS [GMT]Z (z)'
const output = formatToTimeZone(date, format, { timeZone: 'Europe/Berlin' })
`
This module can be installed in your project using [NPM] or [Yarn]. Make sure, that you use [Node.js] version 6 or newer.
`sh`
$ npm i date-fns-timezone --save
`sh`
$ yarn add date-fns-timezone
Functions are exposed as named exports from the package modules, for example:
`js``
const { parseFromTimeZone, formatToTimeZone } = require('date-fns-timezone')
You can read more about the module loading in other environments, like with ES6 or in web browsers. Usage scenarios demonstrate applications of this library in typical real-world scenarios. The API reference lists all functions with a description of their functionality.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
* 2018-10-10 v0.1.4 Fix compatibility with IE. Thanks, Andrii!
* 2018-10-06 v0.1.2 Add TypeScript export declarations.
* 2018-09-19 v0.1.0 Add parseString without a time zone to cover a gap in date-fns
* 2018-09-17 v0.0.1 Initial release
Copyright (c) 2018 Ferdinand Prantl
Licensed under the MIT license.
[IANA time zones]: https://www.iana.org/time-zones
[date-fns]: https://github.com/date-fns/date-fns
[timezone-support]: https://github.com/prantlf/timezone-support
[Node.js]: http://nodejs.org/
[NPM]: https://www.npmjs.com/
[Yarn]: https://yarnpkg.com/
[RequireJS]: https://requirejs.org/