Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smhg/date-time-zone
Create and manipulate time zone specific dates as regular Date objects.
https://github.com/smhg/date-time-zone
Last synced: 4 days ago
JSON representation
Create and manipulate time zone specific dates as regular Date objects.
- Host: GitHub
- URL: https://github.com/smhg/date-time-zone
- Owner: smhg
- License: mit
- Created: 2018-05-05T09:24:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-05T10:46:50.000Z (almost 5 years ago)
- Last Synced: 2025-01-11T15:48:19.838Z (14 days ago)
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
date-time-zone [![Build status](https://api.travis-ci.org/smhg/date-time-zone.png)](https://travis-ci.org/smhg/date-time-zone)
======Create and manipulate time zone specific dates as regular Date objects.
(~Abuses~)Uses [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) and [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy).## Example
```javascript
const { createDate, detectTimeZone } = require('@smhg/date-time-zone');if (!detectTimeZone()) {
console.warn('Time zones not (fully) supported');
}const timeZone = 'Europe/Berlin';
createDate({ timeZone }); // nowcreateDate(2019, 0, 1, { timeZone }); // start of 2019 in Berlin
const date = createDate({ timeZone });
date.setHours(0, 0, 0, 0);
console.log(date.toString()); // start of today in Berlin
```## Usage
When you need to work with a Date instance in another time zone, replace `new Date` with `createDate` and add an options object (`{ timeZone: '...' }`) as the last parameter.All other usage is the same as regular Date objects, with manipulations (`setDate`, `setHours`, ...) happening in the specified time zone and `toString()` returning the date and time in the specified time zone.