Chartjs-Trouble using utcoffset with Chart.js

1👍

I will assume that the reason you want to roll it back by 5 hours is because of a timezone difference. If that’s the case, you should use moment-timezone instead of moment.

With that said, subtracting 5 hours from the current date is actually simpler than what you’re doing.

Before feeding a date into moment, you need to convert it to the js Date object like so: new Date('2021-01-10 00:00:00'). Since your parser function accepts the date in m/d H:M format, you would need to append the year to it first.

So here is how your code should look:

parser: function(utcMoment) {
    const new_date = utcMoment.split(' ')[0] + '/' + (new Date().getFullYear()) + ' ' + utcMoment.split(' ')[1];
    return moment(new Date(new_date)).subtract({hours: 5})
}

Leave a comment