Doubt with moment.js

1

I have a question about the use of moment.js, the question is, if today I put a date and time for example 03/14/2018 at 01:00, I usually keep the UTC time in the database to then format it to the date / time that corresponds depending on the region of the client (hence the use of moment), so far, but I have a problem, which is, instead of being today, for example I put it in August (that there is a different schedule) because I do not see the time well, until you have that kind of schedule, change from +1 to +2 hours depending on the time of year.

So my question is, if I want to set a date time, for example 08/14/2018 at 1, I want to see the 1, be it in March or August, but I do not understand very well how to do this .

I hope any help, thanks.

    
asked by David 14.03.2018 в 10:50
source

2 answers

1

The problem is that when doing the format with moment it takes as default the timezone of the United States, then it changes the schedule. To avoid that, it's a matter of changing the moment.js timezone by adding the moment-timezone library.

For example:

moment.tz("2014-06-01 12:00", "Europe/London");
// Europe/London: 2014-06-01T12:00:00-04:00
moment.tz("2014-06-01 12:00", "America/New_York");
// America/New_York: 2014-06-01T17:00:00+01:00
    
answered by 14.03.2018 / 14:34
source
1

I do not know how you do the time change utc to local time but this is done with the time zone , I do not know if moment.js does this internally because it does not I've used it but you can always do it yourself with the javascript date object:

var d = new Date();
var n = d.getTimezoneOffset(); // te entrega el offset en minutos (+2 = 120)

Now the timezone knows when the time change is, if you ask the offset on August 13 at 23:59 it will tell you for example +1 (60) and if you do it on August 14 at 00:00 will tell you +2 (120).

I hope this serves you, greetings.

    
answered by 14.03.2018 в 12:59