Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smartin85/moment-dt
Convert timestamp-with-timezone-objects from and to moment.js
https://github.com/smartin85/moment-dt
momentjs plugin timestamp timezone
Last synced: 6 days ago
JSON representation
Convert timestamp-with-timezone-objects from and to moment.js
- Host: GitHub
- URL: https://github.com/smartin85/moment-dt
- Owner: smartin85
- License: mit
- Created: 2017-02-12T15:02:55.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T04:01:39.000Z (2 months ago)
- Last Synced: 2024-10-29T16:23:41.941Z (18 days ago)
- Topics: momentjs, plugin, timestamp, timezone
- Language: JavaScript
- Size: 695 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# moment-dt
[![MIT License][license-image]][license-url]
[![npm version][npm-image]][npm-url]
[![npm downloads][downloads-image]][npm-url]
[![Build Status][azure-pipeline-image]][azure-pipeline-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![Known Vulnerabilities][snyk-image]][snyk-url][![Buy me a coffee][buy-me-a-coffee-image]][buy-me-a-coffee-url]
Convert utc-unix-timestamp-with-timezone-objects from and to moment.js
## Getting Started
moment-dt can be included in your app by different ways:### Node.js
moment-dt can be installed with npm and required into a script:
```
npm install --save moment-dt
```
```js
var moment = require('moment-timezone');
require('moment-dt');
```### Browser
Just include the momentjs script and then the moment-dt script:
```html```
### Browser with Require.js
```js
define(["moment-timezone-with-data", "moment-dt"], function (moment) {
// you probably won´t need a reference to moment-dt istself, so include it last
});
```### Bower
```
bower install --save moment-dt
```## Creating a moment from a dt-object
```js
var obj = { ts: 1486920600, tz: "Europe/Berlin" };
var myMoment = moment.dt(obj);myMoment.format();
// "2017-02-12T18:30:00+01:00"moment.dt({ ts: null, tz: "Europe/Berlin" }).format();
// "Invalid date"moment.dt({ ts: 1486920600, tz: null }).format();
// ERR: Moment Timezone has no data for invalid timezone.
// "2017-02-12T18:30:00+01:00" local time
```## Creating a dt-object from a moment
```js
moment.dt({ ts: 1486920600, tz: "Europe/Berlin" }).dt();
// {
// ts: 1486920600,
// tz: "Europe/Berlin"
// }moment.dt({ ts: null, tz: "Europe/Berlin" }).dt();
// {
// ts: null,
// tz: "Europe/Berlin"
// }moment.dt({ ts: 1486920600, tz: null }).dt();
// ERR: Moment Timezone has no data for invalid timezone.
// {
// ts: 1486920600,
// tz: null
// }moment.dt({ ts: 1486920600, tz: "Europe/Berlin" }).add(1, 'year').dt();
// {
// ts: 1518456600,
// tz: "Europe/Berlin"
// }
```[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE[npm-image]: https://badge.fury.io/js/moment-dt.svg
[npm-url]: https://www.npmjs.com/package/moment-dt[downloads-image]: https://img.shields.io/npm/dt/moment-dt.svg
[coveralls-image]: https://coveralls.io/repos/github/smartin85/moment-dt/badge.svg
[coveralls-url]: https://coveralls.io/github/smartin85/moment-dt[snyk-image]: https://snyk.io/test/github/smartin85/moment-dt/badge.svg
[snyk-url]: https://snyk.io/test/github/smartin85/moment-dt[azure-pipeline-image]: https://dev.azure.com/smartin85/moment-dt/_apis/build/status/smartin85.moment-dt?branchName=master
[azure-pipeline-url]: https://dev.azure.com/smartin85/moment-dt/_build/latest?definitionId=3&branchName=master[buy-me-a-coffee-image]: https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png
[buy-me-a-coffee-url]: https://www.buymeacoffee.com/smartin