Heroku timezone issue using Moment.js

In my production / heroku application, the code below returns the number of hours, which is 7 hours more than the number of hours returned by the code below when it runs in my development / local application. Why is this?

var startDate = moment.tz("2000-01-01", "America/Edmonton").startOf('day');
var endDate   = moment.tz("America/Edmonton");

hourly_count = parseInt(endDate.diff( startDate, 'hours' ) + 1 );
+4
source share
3 answers

There is a problem with Heroku. It automatically calculates it in UTC.

the code

var tms = 1492554237000

console.log(moment(tms).format("YYYY-MM-DD HH:mm:ss"))
console.log(moment.utc(tms).format("YYYY-MM-DD HH:mm:ss"))

local output

2017-04-19 06:23:57
2017-04-18 22:23:57

heroku server server

2017-04-18 22:23:57
2017-04-18 22:23:57

I solved this by setting a timestamp.

if (moment().utcOffset() == -0){
    // for server
    tms += 28800000
}

Heroku new server output

2017-04-19 06:23:57
2017-04-19 06:23:57
0
source

, :

  • . , Heroku , .

  • . - . .

    " ", , , moment.tz.add.

, 2014 , .

0

, , , UTC, Moment Timezone. http://momentjs.com/timezone/

-1
source

Source: https://habr.com/ru/post/1537181/


All Articles