Convert utc-unix-timestamp-with-timezone-objects from and to moment.js
moment-dt can be included in your app by different ways:
moment-dt can be installed with npm and required into a script:
npm install --save moment-dt
var moment = require('moment-timezone');
require('moment-dt');
Just include the momentjs script and then the moment-dt script:
<script src="moment.js"></script>
<script src="moment-timezone-with-data.js"></script>
<script src="moment-dt.min.js"></script>
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 install --save moment-dt
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
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"
// }